import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { combineAll } = optic;
Given a Combinable and a function A -> I, collect all values A focused on by an optic into a single value I.
Examples
Example 1
Example 1
import * as O from "./optic.ts";
import { InitializableNumberSum } from "./number.ts";
import { pipe, identity } from "./fn.ts";
type Person = { name: string, age: number };
type People = readonly Person[];
const cumulativeAge = pipe(
O.id<People>(),
O.array,
O.prop("age"),
O.combineAll(InitializableNumberSum, identity),
);
const people: People = [
{ name: "Brandon", age: 37 },
{ name: "Emily", age: 22 },
{ name: "Jackie", age: 47 },
{ name: "Rufus", age: 1 },
];
const result1 = cumulativeAge(people); // 107
const result2 = cumulativeAge([]); // 0