Skip to main content
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.
Go to Latest
function collect
import { collect } from "https://deno.land/x/fun@v2.0.0-alpha.10/record.ts";

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

Examples

Example 1

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

const collectSum = R.collect(MonoidNumberSum);
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