Skip to main content
Module

x/fun/mod.ts>optic.refold

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function optic.refold
import { optic } from "https://deno.land/x/fun@v2.0.0/mod.ts";
const { refold } = optic;

Construct a Refold<S, A> from view, review, and modify functions.

Examples

Example 1

import * as O from "./optic.ts";
import * as S from "./set.ts";

const set = <A>() => O.refold<ReadonlySet<A>, A>(
  Array.from,
  S.wrap,
  S.map,
);

const numberSet = set<number>();

const result1 = numberSet.view(S.set(1, 2, 3)); // [1, 2, 3]
const result2 = numberSet.view(S.init()); // []
const result3 = numberSet.review(1); // Set(1)
const result4 = numberSet.modify(n => n + 1)(S.wrap(1)); // Set(2)

Parameters

view: (s: S) => ReadonlyArray<A>
review: (a: A) => S
modify: (modifyFn: (a: A) => A) => (s: S) => S