fold<L, R, T> function
Transforms an Either using the ifLeft
and ifRight
functions.
expect(
right(1).chain(fold(
(_) => -1,
(number) => number + 1,
)),
equals(2),
);
expect(
left('fail').chain(fold(
(left) => 'caught: $left',
(right) => 'yay!',
)),
equals('caught: fail'),
);
Implementation
T Function(Either<L, R> either) fold<L, R, T>(
T Function(L left) ifLeft,
T Function(R right) ifRight,
) =>
(either) => either._fold(ifLeft, ifRight);