import { decoder } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { intersect } = decoder;
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
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)