fold<A, B> function
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);