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
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