import { concatAll } from "https://deno.land/x/fun@v.2.0.0-alpha.11/optics.ts";
Given a Monoid 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 "./optics.ts";
import { MonoidNumberSum } 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.concatAll(MonoidNumberSum, 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