fold<A, B> function

Task<B> Function(TaskOption<A> taskOption) fold<A, B>(
  1. B onNone(),
  2. B onSome(
    1. A value
    )
)

Transforms the TaskOption into a Task, using the given onNone and onSome callbacks.

expect(
  await some('hello').chain(fold(
    () => 'none',
    (s) => '$s world',
  ))(),
  'hello world',
);
expect(
  await none().chain(fold(
    () => 'none',
    (s) => '$s world',
  ))(),
  'none',
);

Implementation

Task<B> Function(TaskOption<A> taskOption) fold<A, B>(
  B Function() onNone,
  B Function(A value) onSome,
) =>
    T.map(O.fold(onNone, onSome));