Skip to main content
Module

x/fun/decoder.ts>alt

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

Provide an alternative Decoder to fallback against if the first one fails.

Examples

Example 1

import * as D from "./decoder.ts";
import { pipe } from "./fn.ts";

const numOrStr = pipe(
  D.string,
  D.alt(D.number),
);

const result1 = numOrStr(0); // Right(0)
const result2 = numOrStr("Hello"); // Right("Hello")
const result3 = numOrStr(null); // Left(DecodeError)

Returns

<I>(first: Decoder<D, I>) => Decoder<D, A | I>