doOption<A> function

Option<A> doOption<A>(
  1. A f(
    1. B <B>(
      1. Option<B>
      )
    )
)

Implementation

Option<A> doOption<A>(
  A Function(
    B Function<B>(Option<B>),
  ) f,
) {
  try {
    return Some(
      f(
        <B>(option) => switch (option) {
          None() => throw _EvalException(null),
          Some(value: final value) => value
        },
      ),
    );
  } on _EvalException<A> {
    return None();
  }
}