fromPredicate<T> function
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;