safeCastStrict<L, R, V> static method

Either<L, R> safeCastStrict<L, R, V>(
  1. V value,
  2. L onError(
    1. V value

Safely cast a value to type R.

If value is not of type R, then return a Left containing the result of onError.

More strict version of Either.safeCast, in which also the input value type must be specified (while in Either.safeCast the type is dynamic).


static Either<L, R> safeCastStrict<L, R, V>(
  V value,
  L Function(V value) onError,
) =>
    value is R ? Either<L, R>.of(value) : Either<L, R>.left(onError(value));