chainNullableK<L, R, R2> function

Either<L, R2> Function(Either<L, R> value) chainNullableK<L, R, R2>(
  1. R2? f(
    1. R right
    ),
  2. L orElse(
    1. R right
    )
)

A wrapper for fromNullableK, that allows for chaining.

expect(
  right('hello').chain(chainNullableK(
    (s) => s == 'hello' ? s : null,
    () => 'it was not hello',
  )),
  right('hello'),
);

expect(
  right('asdf').chain(chainNullableK(
    (s) => s == 'hello' ? s : null,
    () => 'it was not hello',
  )),
  left('it was not hello'),
);

Implementation

Either<L, R2> Function(Either<L, R> value) chainNullableK<L, R, R2>(
  R2? Function(R right) f,
  L Function(R right) orElse,
) =>
    flatMap(fromNullableK(f, orElse));