Created
November 5, 2014 01:20
-
-
Save shajra/a73af60af7d88bc54549 to your computer and use it in GitHub Desktop.
Is this idea for a Phantom-like operator reasonable?
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
implicit class IdOps[A](a: A) { | |
def callNullable[B](f: A => B): Maybe[B] = | |
if (a != null) { | |
val b = f(a) | |
if (b != null) Maybe.just(b) else Maybe.empty | |
} else Maybe.empty | |
def ?>[B](f: A => B): Maybe[B] = callNullable(f) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment