Skip to content

Instantly share code, notes, and snippets.

@julien-truffaut
Created October 22, 2016 21:10
Show Gist options
  • Save julien-truffaut/624042fea469ce73c421f1413580db02 to your computer and use it in GitHub Desktop.
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
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