mapOrElse<R> method
R
mapOrElse<R>(
- R fallback(
- E error
- R mapper(
- T value
Maps a successful value, or computes a fallback from the error.
Only the branch that applies is called.
final label = const Err<int, String>('offline')
.mapOrElse((error) => 'failed: $error', (n) => '$n items');
Implementation
R mapOrElse<R>(R Function(E error) fallback, R Function(T value) mapper) {
return switch (this) {
Ok<T, E>(:final value) => mapper(value),
Err<T, E>(:final error) => fallback(error),
};
}