Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/fun/record.ts>collect

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

Collect all values in a ReadonlyRecord into a single value I by using a Combinable and a mapping function from A to I. This is effectively fold using a Combinable for the initial value.

Examples

Example 1

import * as R from "./record.ts";
import { InitializableNumberSum } from "./number.ts";
import { pipe } from "./fn.ts";

const collectSum = R.collect(InitializableNumberSum);
const collectLengths = collectSum((s: string) => s.length);

const result = collectLengths({ one: "one", two: "two" }); // 6

Returns

<A>(fai: (a: A, index: string) => I) => (ua: ReadonlyRecord<A>) => I