Created
October 22, 2016 21:10
-
-
Save julien-truffaut/624042fea469ce73c421f1413580db02 to your computer and use it in GitHub Desktop.
SO: How do I pull apart Case Classes filled with Options in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import monocle.macros.GenIso | |
import scalaz.std.option._ | |
object Test extends App { | |
case class Bar(blub: Option[String]) | |
case class Foo(bar: Option[Bar]) | |
val bar = GenIso[Foo, Option[Bar]] | |
val blub = GenIso[Bar, Option[String]] | |
val s = bar composePrism blub.asPrism.below[Option] | |
s.reverseGet(Some(Some("Hello"))) | |
s.reverseGet(Some(None)) | |
s.reverseGet(None) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment