Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def thenF[A, B](v: Option[A])(f: A => Option[B]): Option[B] = {
- if (v.nonEmpty) {
- f(v.get)
- } else {
- None
- }
- }
- val mayFail: Option[User] = Option(null)
- val ok: Option[User] = Option(User(123))
- thenF(mayFail)(getInfoOpt) // res16: Option[Info] = None
- thenF(ok)(getInfoOpt) // res17: Option[Info] = Some(Info(Tom))
Add Comment
Please, Sign In to add comment