Skip to content

fromPredicate

fromPredicate<A>(pred): (a) => Maybe<A>

Defined in: Core/Maybe.ts:83

Creates a Maybe from a predicate applied to a value. Returns Some if the predicate passes, None otherwise.

A

(a) => boolean

(a) => Maybe<A>

Maybe.fromPredicate((n: number) => n >= 18)(21); // Some(21)
Maybe.fromPredicate((n: number) => n >= 18)(15); // None

pipe("hello", Maybe.fromPredicate((s: string) => s.length > 0)); // Some("hello")
pipe("", Maybe.fromPredicate((s: string) => s.length > 0));      // None