Either<L, R>.safeCast constructor

Either<L, R>.safeCast(
  1. dynamic value,
  2. L onError(
    1. dynamic value

Safely cast a value to type R.

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

Less strict version of Either.safeCastStrict, since safeCast assumes the value to be dynamic.

Note: Make sure to specify the types of Either (Either<L, R>.safeCast instead of Either.safeCast), otherwise this will always return Right!


factory Either.safeCast(
  dynamic value,
  L Function(dynamic value) onError,
) =>
    Either.safeCastStrict<L, R, dynamic>(value, onError);