Skip to main content
Module

x/fun/predicate.ts>Predicate

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

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

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