import type { DeepPath, Fn2, Path, Path0, Path1, Path2, Path3, Path4, Path5, Path6, Path7, Path8, PathVal } from "@thi.ng/api"; /** * Composes a setter function for given nested update path. Optimized * fast execution paths are provided for path lengths less up to 4. * * @remarks * Supports both arrays and objects and creates intermediate shallow * copies at each level of the path. Thus provides structural sharing * with the original data for any branches not being updated by the * setter. * * The type parameter `T` can be used to indicate the type of the nested * value to be updated (default: `any`). * * If `path` is given as string, it will be split using `.`. Returns * function which accepts single object and when called, **immutably** * updates value at given path, i.e. produces a partial deep copy of obj * up until given path. * * If any intermediate key is not present in the given obj, creates a * plain empty object for that key and descends further. * * If `path` is an empty string or array, the returned setter will * simply return the new value. * * Only keys in the path will be modified, all other keys present in the * given object retain their original values to provide efficient * structural sharing / re-use. * * @example * ```ts tangle:../export/def-setter-unsafe.ts * import { defSetterUnsafe } from "@thi.ng/paths"; * * const s = defSetterUnsafe("a.b.c"); * // or * // const s = defSetterUnsafe(["a", "b", "c"]); * * console.log( * s({ a: { b: { c: 23} } }, 24) * ); * // { a: { b: { c: 24} } } * * console.log( * s({ x: 23 }, 24) * ); * // { x: 23, a: { b: { c: 24 } } } * * console.log( * s(null, 24) * ); * // { a: { b: { c: 24 } } } * ``` * * @example * ```ts tangle:../export/def-setter-unsafe-2.ts * import { defSetterUnsafe } from "@thi.ng/paths"; * * const s = defSetterUnsafe("a.b.c"); * * const a = { x: { y: { z: 1 } } }; * const b = s(a, 2); * * console.log(b); * // { x: { y: { z: 1 } }, a: { b: { c: 2 } } } * * console.log(a.x === b.x); // true * console.log(a.x.y === b.x.y); // true * ``` * * @param path - */ export declare const defSetterUnsafe: (path: Path) => Fn2; /** * Type checked version of {@link defSetterUnsafe}. Only the first 8 * path levels are type checked. * * @remarks * Due to the higher-order nature of this function, generics for path * validation must be given and so this function is more verbose than * {@link setIn} (where the generics can usually be fully inferred). * * @example * ```ts tangle:../export/def-setter.ts * import { defSetter } from "@thi.ng/paths"; * * type State = { a: { b: number } }; * * const setB = defSetter(["a", "b"]); * * setB({ a: { b: 1 } }, 2); // ok! * setB({ a: { b: 1 } }, "2"); // error! * ``` * * @example * ```ts tangle:../export/def-setter-2.ts * import { defSetter } from "@thi.ng/paths"; * * type State = { a: { b: number } }; * * const path = ["a","b"]; * * const setB = defSetter(path); * ``` * * @param path - */ export declare function defSetter(path: Path0): Fn2; export declare function defSetter(path: Path1): Fn2, T>; export declare function defSetter(path: Path2): Fn2, T>; export declare function defSetter(path: Path3): Fn2, T>; export declare function defSetter(path: Path4): Fn2, T>; export declare function defSetter(path: Path5): Fn2, T>; export declare function defSetter(path: Path6): Fn2, T>; export declare function defSetter(path: Path7): Fn2, T>; export declare function defSetter(path: Path8): Fn2, T>; export declare function defSetter(path: DeepPath): Fn2; /** * Creates a shallow copy of given array, typed array or plain object. * * @param x - */ export declare const copy: (x: any) => any; //# sourceMappingURL=setter.d.ts.map