Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/fn_either.ts>fromPredicate

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

Create a FnEither from a Predicate or a Refinement. If the Predicate or Refinement returns true then the FnEither returns Right, otherwise it returns Left.

Examples

Example 1

import * as FE from "./fn_either.ts";
import { pipe } from "./fn.ts";

const isPositive = (n: number) => n > 0;
const computation = FE.fromPredicate(isPositive);

const result1 = computation(0); // Left(0)
const result2 = computation(1); // Right(1)

Type Parameters

A
B extends A

Parameters

refinement: Refinement<A, B>