This is a similar question to Why doesn't Option have a fold method?, but for functional-java.

I want to perform some side-effect if an option is None. Is there something I can use other than if maybeT.isNone()?

I'm thinking along the lines of Option<B> optionA.fold(Effect<Unit> none, F<A, B> some).

Is there something that already exists?

有帮助吗?

解决方案

You could use the option method

public final <B> B option(final P1<B> b, final F<A, B> f) {
  return isSome() ? f.f(some()) : b._1();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top