Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/decoder.ts>struct

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

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]>