Either<L, R>.safeCast constructor
Either<L, R>.safeCast (
- 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`s are use for safe-casting
//ignore: avoid_annotating_with_dynamic
dynamic value,
// `dynamic`s are use for safe-casting
//ignore: avoid_annotating_with_dynamic
L Function(dynamic value) onError,
) =>
Either.safeCastStrict<L, R, dynamic>(value, onError);