fromPredicateMap<A, B> static method
- A value,
- bool predicate(
- A a
- B f(
- 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();