Guest User

Untitled

a guest
Jun 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. def thenNullCheck[A, B, C](f: A => B, g: B => C) = {
  2. optional(f).andThen(optional(g))
  3. }
  4. val nullCheckedComposition = thenNullCheck(getUser, getInfo) // nullCheckedComposition: Long => Info
  5. nullCheckedComposition(null.asInstanceOf[Int]) // res10: Info = null
  6. nullCheckedComposition(123) // res11: Info = Info(Tom)
  7. nullCheckedComposition(1234) // res12: Info = null
Add Comment
Please, Sign In to add comment