Skip to main content
Module

x/fun/mod.ts>refinement.fromOption

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

Construct a refinement from a function (a: A) => Option where None denotes that a type does not satisfy the refinement.

Examples

Example 1

import * as R from "./refinement.ts";
import * as O from "./option.ts";

const refine = R.fromOption((u: unknown) => typeof u === "number" ? O.some(u)
: O.none);
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) => Option<B>