Created
May 3, 2018 09:24
-
-
Save JoolsF/cdd4c3e144331709112b8bd48fe13168 to your computer and use it in GitHub Desktop.
Lift example 2
This file contains hidden or 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
| def lift3[A, B, C, D](f: Function3[A, B, C, D]): Function3[Option[A], Option[B], Option[C], Option[D]] = { | |
| (oa: Option[A], ob: Option[B], oc: Option[C]) => | |
| for { | |
| a <- oa | |
| b <- ob | |
| c <- oc | |
| } yield f(a, b, c) | |
| } | |
| case class Foo(a: Int, b: Int, c: Int) | |
| def getFoo(a: Int, b: Int, c: Int): Foo = Foo(a, b, c) | |
| val liftGetFoo: (Option[Int], Option[Int], Option[Int]) => Option[Foo] = lift3(getFoo) | |
| val a = Option(1) | |
| val b = Option(2) | |
| val c = Option(3) | |
| liftGetFoo(a, b, c) // Some(Foo(1,2,3)) | |
| liftGetFoo(a, b, None ) // None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment