Skip to main content
Module

x/fun/optic.ts>replace

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

A pipeable replace function, that uses the modify function of an Optic to replace an existing value over the structure S.

Examples

Example 1

import * as O from "./optic.ts";
import { pipe } from "./fn.ts";

type Person = { name: string };

const name = pipe(O.id<Person>(), O.prop("name"));
const toBrandon = pipe(name, O.replace("Brandon"));

const tina: Person = { name: "Tina" }

const result = toBrandon(tina); // { name: "Brandon" }

Returns

<S>(modifier: Modifier<S, A>) => (s: S) => S