Skip to main content
Module

x/fun/mod.ts>fn_either.fromPredicate

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

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>