fold<A, B> function

B Function(Option<A> option) fold<A, B>(
  1. B ifNone(),
  2. B ifSome(
    1. A value
    )
)

Transforms an Option into a value, using the ifNone and ifSome functions.

expect(
  some(1).chain(fold(
    () => 'no',
    (number) => 'got $number',
  )),
  'got 1',
);
expect(
  none().chain(fold(
    () => 'no',
    (number) => 'got $number',
  )),
  'no',
);

Implementation

B Function(Option<A> option) fold<A, B>(
  B Function() ifNone,
  B Function(A value) ifSome,
) =>
    (option) => option._fold(ifNone, ifSome);