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 unzip instance for Getter #458

Merged
merged 1 commit into from Dec 20, 2016
Merged

Add unzip instance for Getter #458

merged 1 commit into from Dec 20, 2016

Conversation

swsnr
Copy link
Contributor

@swsnr swsnr commented Dec 16, 2016

Closes GH-455

@julien-truffaut While I was at it :)

@julien-truffaut
Copy link
Member

if you get the time, could you also add unzip to the Getter class, the signature should probably look like this:

import scalaz.Leibniz.===
def unzip[B, C](implicit ev: (B, C) === A): (Getter[S, B], Getter[S, C])

but we should check that type inference works with something like:

getterA.zip(getterB).unzip

see also https://github.com/julien-truffaut/Monocle/blob/master/core/shared/src/main/scala/monocle/Prism.scala#L246

@swsnr
Copy link
Contributor Author

swsnr commented Dec 19, 2016

I added the instance method to Getter, but it doesn't look like type inference can cope with it. The compiler won't find the implicit evidence for === unless you explicitly give type parameters to unzip.

val length = Getter[String, Int](_.length)
val upper = Getter[String, String](_.toUpperCase)

val (length1, upper1) = length.zip(upper).unzip[Int, String]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to give the type parameters to .unzip explicitly to make the compiler find the implicit evidence for ===. Without explicit type parameters it wouldn't compile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arf ok, maybe we should revert back to your first commit if we can't get the type inference to work properly

@swsnr
Copy link
Contributor Author

swsnr commented Dec 20, 2016

@julien-truffaut I dropped the .unzip instance method again.

@julien-truffaut
Copy link
Member

@lunaryorn sorry for the back and force. Thank you very much 👍

@swsnr
Copy link
Contributor Author

swsnr commented Dec 20, 2016

@julien-truffaut Never mind; I learned a bit about scalaz along the way for I never actually used it before.

@julien-truffaut julien-truffaut merged commit 097b7d5 into optics-dev:master Dec 20, 2016
@swsnr swsnr deleted the unzip branch December 20, 2016 08:46
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.

None yet

2 participants