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

x/rimbu/deep/index.ts>Deep.patch

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function Deep.patch
import { Deep } from "https://deno.land/x/rimbu@1.0.2/deep/index.ts";
const { patch } = Deep;

Returns an immutably updated version of the given value where the given patchItems have been applied to the result. The Rimbu patch notation is as follows:

  • if the target is a simple value or array, the patch can be the same type or a function returning the same type
  • if the target is a tuple (array of fixed length), the patch be the same type or an object containing numeric keys with patches indicating the tuple index to patch
  • if the target is an object, the patch can be the same type, or an array containing partial keys with their patches for the object

Examples

Example 1

const input = { a: 1, b: { c: true, d: 'a' } }
patch(input, [{ a: 2 }])  // => { a: 2, b: { c: true, d: 'a' } }
patch(input, [{ b: [{ c: (v) => !v }] }] )
// => { a: 1, b: { c: false, d: 'a' } }
patch(input: [{ a: (v) => v + 1, b: [{ d: 'q' }] }] )
// => { a: 2, b: { c: true, d: 'q' } }

Type Parameters

T
optional
TE extends T = T
optional
TT = T

Parameters

value: T
  • the input value to patch
patchItem: Patch<TE, T & TT>
  • the Patch value to apply to the input value