filter<L, R> function

TaskEither<L, R> Function(TaskEither<L, R> taskEither) filter<L, R>(
  1. bool predicate(
    1. R value
    ),
  2. L orElse(
    1. R value
    )
)

Conditionally filter the TaskEither, transforming Right values to Left.

expect(
  await right('hello').chain(filter(
    (s) => s == 'hello',
    (s) => '$s was not hello',
  ))(),
  E.right('hello'),
);
expect(
  await right('asdf').chain(filter(
    (s) => s == 'hello',
    (s) => '$s was not hello',
  ))(),
  E.left('asdf was not hello'),
);

Implementation

TaskEither<L, R> Function(TaskEither<L, R> taskEither) filter<L, R>(
  bool Function(R value) predicate,
  L Function(R value) orElse,
) =>
    (fa) => TaskEither(fa.p(task.map(either.filter(predicate, orElse))));