Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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>
function fromPredicate<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>;
function fromPredicate<A>(refinement: Predicate<A>): (a: A) => Option<A>;
function fromPredicate<A>(predicate: Predicate<A>);
§
fromPredicate<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>
[src]

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>

§Type Parameters

§
B extends A
[src]

§Parameters

§
refinement: Refinement<A, B>
[src]

§Return Type

§
(a: A) => Option<B>
[src]
§
fromPredicate<A>(refinement: Predicate<A>): (a: A) => Option<A>
[src]

§Type Parameters

§Parameters

§
refinement: Predicate<A>
[src]

§Return Type

§
(a: A) => Option<A>
[src]
§
fromPredicate<A>(predicate: Predicate<A>)
[src]

§Type Parameters

§Parameters

§
predicate: Predicate<A>
[src]