This common pattern feels a bit verbose:
if (condition)
Some(result)
else None
I was thinking of using a function to simplify:
def on[A](cond: Boolean)(f: => A) = if (cond) Some(f) else None
This reduces the top example to:
on (condition) { result }
Does something like this exist already? Or is this overkill?
You could create the
Option
first and filter on that with your condition:or if
condition
is not related toresult