map<Y extends Object?> method
Transforms the success value using block, leaving errors unchanged.
If this is Ok, applies block to the value and wraps the result in Ok.
If this is Err, returns the same error unchanged. The error type remains
the same; for transforming errors, use mapErr instead.
This is useful for value transformations that can't fail. For operations that might fail, use andThen (flatMap) instead. Errors short-circuit the transformation and are returned immediately.
Example:
Result<int, String> result = Ok(5);
final doubled = result.map((value) => value * 2); // Ok(10)
Result<int, String> error = Err('failed');
final doubled2 = error.map((value) => value * 2); // Err('failed')
Implementation
Result<Y, E> map<Y extends Object?>(Y Function(T value) block) =>
switch (this) {
Err<T, E>(:final error, :final stackTrace) => .err(error, stackTrace),
Ok<T, E>(:final value) => .ok(block(value)),
};