Skip to main content
Module

x/fun/record.ts>sequence

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 sequence
import { sequence } from "https://deno.land/x/fun@v2.0.0-alpha.10/record.ts";

Sequence over an ReadonlyRecord of type V, inverting the relationship between V and ReadonlyRecord. This function also keeps the indexed types of in each V at covariant position 0. In other words sequence over [Option, Option] becomes Option<[number, string]>.

Examples

Example 1

import * as R from "./record.ts";
import * as O from "./option.ts";

const sequence = R.sequence(O.ApplicativeOption);

const result1 = sequence({ one: O.some(1), two: O.some("Hello")}); // Some({ one: 1, two: "Hello"})
const result2 = sequence({ one: O.none, two: O.some("Uh Oh")}); // None

Returns

<VS extends ReadonlyRecord<AnySub<V>>>(values: NonEmptyRecord<VS>) => Sequence<V, VS>