Skip to main content
Module

x/fun/decoder.ts>undefinable

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

A decoder combinator that modifies an existing decoder to accept undefined as an input value and a successful return value.

Examples

Example 1

import * as D from "./decoder.ts";

const orUndefined = D.undefinable(D.string);

const result1 = orUndefined(undefined); // Right(null)
const result2 = orUndefined(2); // Left(DecodeError)
const result3 = orUndefined("Hello"); // Right("Hello")

Returns

Decoder<D | undefined, A | undefined>