Skip to main content
Module

x/fun/decoder.ts>literal

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 literal
import { literal } from "https://deno.land/x/fun@v2.0.0-alpha.10/decoder.ts";

Create a Decoder from a list of literal values. Literal values can be strings, numbers, booleans, null, or undefined. This decoder will only return Right if the value being decoded has object equality with one of the literals supplied.

Examples

Example 1

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

const firstThree = D.literal(1, 2, 3);

const result1 = firstThree(0); // Left(DecodeError)
const result2 = firstThree(1); // Right(1)
const result3 = firstThree(2); // Right(2)
const result4 = firstThree(3); // Right(3)
const result5 = firstThree(null); // Left(DecodeError)

Parameters

...literals: A

Returns

Decoder<unknown, A[number]>