Either<L, R>.safeCast constructor
Null safety
- dynamic value,
- L onError(
- 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!
Implementation
factory Either.safeCast(
dynamic value,
L Function(dynamic value) onError,
) =>
Either.safeCastStrict<L, R, dynamic>(value, onError);