Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>optic.combineAll

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function optic.combineAll
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

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

Parameters

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

Returns

<U extends Tag, S>(first: Optic<U, S, A>) => (s: S) => I