fromPredicateMap<A, B> static method

Option<B> fromPredicateMap<A, B>(
  1. A value,
  2. bool predicate(
    1. A a
    ),
  3. B f(
    1. A a
    )
)

Return Some of type B by calling f with value when predicate applied to value is true, None otherwise.

/// If the value of `str` is not empty, then return a [Some] containing
/// the `length` of `str`, otherwise [None].
Option.fromPredicateMap<String, int>(
  str,
  (str) => str.isNotEmpty,
  (str) => str.length,
);

Implementation

static Option<B> fromPredicateMap<A, B>(
        A value, bool Function(A a) predicate, B Function(A a) f) =>
    predicate(value) ? Some(f(value)) : Option.none();