Skip to main content
Module

x/fun/mod.ts>option.fromPredicate

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

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.

Examples

Example 1

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>

Type Parameters

A
B extends A

Parameters

refinement: Refinement<A, B>

Returns

(a: A) => Option<B>

Parameters

refinement: Predicate<A>

Returns

(a: A) => Option<A>