fold<L, R, A> function

Task<A> Function(TaskEither<L, R> taskEither) fold<L, R, A>(
  1. A onLeft(
    1. L left
    ),
  2. A onRight(
    1. R right
    )
)

Unwraps the Either value, returning a Task that resolves to the result.

onRight is run if the value is an Right, and onLeft for Left.

expect(
  await right('hello').chain(fold(
    (left) => 'left value',
    (right) => 'right value',
  ))(),
  'right value',
);
expect(
  await left('fail').chain(fold(
    (left) => 'left value',
    (right) => 'right value',
  ))(),
  'left value',
);

Implementation

Task<A> Function(TaskEither<L, R> taskEither) fold<L, R, A>(
  A Function(L left) onLeft,
  A Function(R right) onRight,
) =>
    task.map(either.fold(onLeft, onRight));