Skip to main content
Module

x/fun/decoder.ts>arrayN

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function arrayN
import { arrayN } from "https://deno.land/x/fun@v.2.0.0-alpha.11/decoder.ts";

A Decoder that checks that an object is both an Array and that it's length is N.

Examples

Example 1

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

const two = D.arrayN(2);

const result1 = two(null); // Left(DecodeError)
const result2 = two([]); // Left(DecodeError)
const result3 = two(["hello"]); // Left(DecodeError)
const result4 = two(["hello", 2]); // Right(["hello", 2])

Type Parameters

N extends number

Parameters

length: N

Returns

Decoder<unknown, Array<unknown> & { length: N; }>