Skip to main content
Module

x/fun/mod.ts>decoder.struct

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

A decoder over a heterogenous record type. This struct can have different values at each key, and the resultant decoder will ensure that each key matches its corresponding decoder.

Examples

Example 1

import * as D from "./decoder.ts";

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

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

Parameters

items: [K in keyof A]: Decoder<unknown, A[K]>

Returns

Decoder<unknown, readonly [K in keyof A]: A[K]>