Skip to main content
Module

x/fun/mod.ts>refinement.fromEither

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

Construct a refinement from a function (a: A) => Either<J, I> where Left denotes that a type does not satisfy the refinement.

Examples

Example 1

import * as R from "./refinement.ts";
import * as E from "./either.ts";

const refine = R.fromEither((u: unknown) => typeof u === "number" ? E.right(u)
: E.left(u));
const value1: unknown = "Hello";
const value2: unknown = 0;

const result1 = refine(value1); // false, value1: unknown
const result2 = refine(value2); // true, value2: number

Type Parameters

A
B extends A

Parameters

faob: (a: A) => Either<unknown, B>