map<U, E extends Exception> method

Result<U, F> map<U, E extends Exception>(
  1. U transform(
    1. S
    )
)

Maps a Result<S, F> to Result<U, F> by applying a function to a contained Success value, leaving an Failure value untouched. This function can be used to compose the results of two functions.

Example usage.

Apply transformation to successful operation results or handle an error:

final result = await getPhotos();

if (result.isSuccess) {
  final items = result.map((i) => i.where((j) => j.title.length > 60)).success;
  print('Number of Long Titles: ${items.length}');
} else {
  print('Error: ${result.failure}');
}

Implementation

Result<U, F> map<U, E extends Exception>(U Function(S) transform) {
  if (isSuccess) {
    return Success(transform(_left.value));
  } else {
    return Failure(_right.value);
  }
}