import { Deep } from "https://deno.land/x/rimbu@1.0.2/deep/internal.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
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' } }