import { type predicate } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { Predicate } = predicate;
The Predicate type is a function that takes some value of type A and returns boolean, indicating that a property is true or false for the value A.
Examples
Example 1
Example 1
import type { Predicate } from "./predicate.ts";
import * as O from "./option.ts";
function fromPredicate<A>(predicate: Predicate<A>) {
return (a: A): O.Option<A> => predicate(a)
? O.some(a) : O.none;
}
function isPositive(n: number): boolean {
return n > 0;
}
const isPos = fromPredicate(isPositive);
const resultSome = isPos(1); // Some(1)
const resultNone = isPos(-1); // None
definition: (a: A) => boolean