fromPredicate
import { fromPredicate } from "https://raw.githubusercontent.com/baetheus/fun/main/option.ts";
The fromPredicate function will test the value a with the predicate. If the predicate evaluates to false then the function will return a None, otherwise it will return the value wrapped in Some.
@example
import * as O from "./option.ts";
const positive = O.fromPredicate((n: number) => n > 0);
const result1 = positive(-1); // None
const result2 = positive(1); // Some<number>
§
The fromPredicate function will test the value a with the predicate. If the predicate evaluates to false then the function will return a None, otherwise it will return the value wrapped in Some.
@example
import * as O from "./option.ts";
const positive = O.fromPredicate((n: number) => n > 0);
const result1 = positive(-1); // None
const result2 = positive(1); // Some<number>
§Parameters
§
refinement: Refinement<A, B>
[src]