Skip to main content
Module

x/fun/mod.ts>optics.combineAll

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 optics.combineAll
import { optics } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { combineAll } = optics;

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

import * as O from "./optics.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

Parameters

initializable: Initializable<I>
fai: (a: A) => I