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

x/fun/mod.ts>optic.replace

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

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