Skip to main content
Module

x/fun/option.ts>fromPredicate

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function fromPredicate
import { fromPredicate } from "https://deno.land/x/fun@v2.0.0-alpha.6/option.ts";

fromPredicate will test the value a with the predicate. If the predicate evaluates to false then the function will return a None, otherwise the value wrapped in Some

TODO: Overload with refinement

Examples

const fromPositiveNumber = fromPredicate((n: number) => n > 0); const a = fromPositiveNumber(-1); // None const a = fromPositiveNumber(1); // Some

Type Parameters

A
B extends A

Parameters

refinement: Refinement<A, B>

Returns

(a: A) => Option<B>