Skip to main content
Module

x/rimbu/mod.ts>patch

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function patch
Re-export
import { patch } from "https://deno.land/x/rimbu@0.10.0/mod.ts";

Returns an updated version of given value, without modifying the value, where the contents are updated according to the given patches Patch array.

Examples

Example 1

patch({ g: { h: 5 }})({ g: { h: 6 }})          // => { g: { h: 6 }}
patch({ g: { h: 5 }})({ g: { h: v => v + 1 }}) // => { g: { h: 6 }}
patch({ g: { h: 5 }})({ g: { h: 1 }}, { g: { h: v => v + 1 }})
// => { g: { h: 2 }}
patch({ a: 1, b: 3 })({ a: (v, p) => v * p.b, (v, p) => v + p.a })
// => { a: 3, b: 4 }

Parameters

value: T
  • the value to update

Returns

(...patches: Patch.Multi<T>) => T