fromPredicate<T> function

Option<T> fromPredicate<T>(
  1. T value,
  2. bool predicate(
    1. T value
    )
)

Returns a Some or None if the predicate returns true or false respectively.

expect(fromPredicate('hello', (_) => true), some('hello'));
expect(fromPredicate('hello', (_) => false), none());
expect(fromPredicate('hello', (str) => str == 'hello'), some('hello'));

Implementation

Option<T> fromPredicate<T>(T value, bool Function(T value) predicate) =>
    predicate(value) ? some(value) : kNone;