fromNullableK<A, L, R> function

Either<L, R> Function(A value) fromNullableK<A, L, R>(
  1. R? f(
    1. A value
    ),
  2. L orElse(
    1. A value
    )
)

A wrapper for fromNullable, that returns a function that accepts a value to be transformed.

final transform = fromNullableK(
  (String s) => s == 'hello' ? s : null,
  () => 'it was not hello',
);

expect(
  transform('hello'),
  right('hello'),
);

expect(
  transform('asdf'),
  left('it was not hello'),
);

Implementation

Either<L, R> Function(A value) fromNullableK<A, L, R>(
  R? Function(A value) f,
  L Function(A value) orElse,
) =>
    (value) => fromNullable(f(value), () => orElse(value));