mapMaybe<U> method

Maybe<List<U>> mapMaybe<U>(
  1. Maybe<U> tryMap(
    1. T
    )
)

Traverses an iterable trying to map the elements with tryMap, returning None if either the iterable was empty or the result of every mapping operation was None.

Implementation

Maybe<List<U>> mapMaybe<U>(Maybe<U> Function(T) tryMap) {
  final results = expand((e) => tryMap(e).toList());
  return results.isEmpty ? None<List<U>>() : Just(results.toList());
}