Skip to main content
Module

x/fun/decoder.ts>union

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

Provide an alternative Decoder to fallback against if the first one fails. This is an alias of alt.

Examples

Example 1

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

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

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

Returns

<A>(left: Decoder<B, A>) => Decoder<B, A | I>