Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tuple syntax #248

Merged
merged 17 commits into from
Oct 28, 2021
Merged

Add tuple syntax #248

merged 17 commits into from
Oct 28, 2021

Conversation

danicheg
Copy link
Member

@danicheg danicheg commented Oct 11, 2021

This PR brings 4 handy methods for tuples (for Scala 2 only):

val foo = (1, 2, 4).head // 1
val bar = (1, 2, 4).init // (1, 2)
val baz = (1, 2, 4).last // 4
val qux = (1, 2, 4).tail // (2,4)

That functionality there is in shapeless https://github.com/milessabin/shapeless/blob/main/core/src/main/scala/shapeless/syntax/std/tuples.scala#L30. However, bringing shapeless as a dependency just for tuple syntax is overkill, I think. What's more, implementation in mouse is plain and not used type-level magic, so it will not affect compile time at all.

@benhutchison
Copy link
Member

Thats cool! I always liked init and last on List.

I have one future-oriented query. Scala 3 is released and gradually the community will migrate to it. The implementation of init and last in 3+ would be more elegant and not subject to arity limit. Assuming they don't offer these methods in core lib, are we stuck with clunky 2.x approach forever more for compat reasons..? Or can a future 3.x+ only version of mouse offer these operations built on top of "HList tuple" model?

@danicheg
Copy link
Member Author

@benhutchison thanks for the review! I have pondered about init and last methods on tuples in Scala 3 and eventually make a PR to core lib. So if core lib will have those methods, it makes sense to have the syntax in mouse only for Scala 2. So this PR will be waiting for a decision on scala/scala3#13735.

@danicheg
Copy link
Member Author

@benhutchison PR in dotty was merged, so I've changed tuple syntax to be available only for Scala 2.

@benhutchison
Copy link
Member

@danicheg apology for slows, I like the plan to make avail in 2.12 only and your PR to core 👏

@danicheg
Copy link
Member Author

@benhutchison sorry for yet another ping. I have ended up working on this and would be extremely glad for your review.

@danicheg danicheg mentioned this pull request Oct 22, 2021
3 tasks
@danicheg danicheg merged commit 94df16a into main Oct 28, 2021
@danicheg danicheg deleted the tuple-syntax branch October 28, 2021 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants