Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>decoder.nullable

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

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

Examples

Example 1

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

const orNull = D.nullable(D.string);

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

Returns

Decoder<D | null, A | null>