I have a Boolean and would like to avoid this pattern:
if (myBool) Option(someResult) else None
What I\'d like to do is
Another choice:
implicit class RichOptionCompanion(val self: Option.type) extends AnyVal { def when[A](cond: Boolean)(value: => A): Option[A] = if(cond) Some(value) else None }
Usage:
Option.when(foo != "bar") { ... }