Skip to main content
Module

x/fun/refinement.ts>fromEither

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 fromEither
import { fromEither } from "https://deno.land/x/fun@v.2.0.0-alpha.11/refinement.ts";

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>