質問

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