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

x/fun/mod.ts>decoder.array

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

A decoder against an array with only values that adhere to the passed in items decoder.

Examples

Example 1

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

const strings = D.array(D.string);

const result1 = strings(null); // Left(DecodeError)
const result2 = strings({}); // Left(DecodeError)
const result3 = strings([]); // Right([])
const result4 = strings([1, 2, 3]); // Left(DecodeError)
const result5 = strings(["one", "two"]); // Right(["one", "two"])

Parameters

items: Decoder<unknown, A>

Returns

Decoder<unknown, ReadonlyArray<A>>