Skip to content

Instantly share code, notes, and snippets.

@shajra
Created November 5, 2014 01:20
Show Gist options
  • Save shajra/a73af60af7d88bc54549 to your computer and use it in GitHub Desktop.
Save shajra/a73af60af7d88bc54549 to your computer and use it in GitHub Desktop.
Is this idea for a Phantom-like operator reasonable?
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