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

Predicate

import type { Predicate } from "https://raw.githubusercontent.com/baetheus/fun/main/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.

@example
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
type Predicate<A> = (a: A) => boolean;

§Type Parameters

§Type

§
(a: A) => boolean
[src]