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