Skip to main content
Module

x/fun/decoder.ts>intersect

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

A Decoder combinator that intersects two existing decoders. The resultant decoder ensures that an input matches both decoders. Nested intersection combinators will combine and flatten their error trees.

Examples

Example 1

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

const person = pipe(
  D.struct({ name: D.string }),
  D.intersect(D.partial({ age: D.string })),
);

const result1 = person(null); // Left(DecodeError)
const result2 = person({ name: "Brandon" }); // Right({ name: "Brandon" })
const result3 = person({ name: "Brandon", age: 37 });
// Right({ name: "Brandon", age: 37 })
const result4 = person({ age: 37 }); // Left(DecodeError)

Returns

<A>(first: Decoder<B, A>) => Decoder<B, Spread<A & I>>