import type { DeepPath , Fn2 , NumOrString , Path , Path0 , Path1 , Path2 , Path3 , Path4 , Path5 , Path6 , Path7 , Path8 , PathVal , } from "@thi.ng/api" ; import { isArray } from "@thi.ng/checks/is-array" ; import { isTypedArray } from "@thi.ng/checks/is-typedarray" ; import { toPath } from "./path.js" ; remarks example example param path export const defSetterUnsafe = < T = any > ( path ) : Fn2 < any , T , any > => defSetter ( < any > path ) ; /**
 * Type checked version of  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
 *  setIn (where the generics can usually be fully inferred).
 *
 *  example example param path export function defSetter < T > ( path ) ; export function defSetter < T , A > ( path ) ; export function defSetter < T , A , B > ( path ) ; export function defSetter < T , A , B , C > ( path ) ; export function defSetter < T , A , B , C , D > ( path ) ; export function defSetter < T , A , B , C , D , E > ( path ) ; export function defSetter < T , A , B , C , D , E , F > ( path ) ; export function defSetter < T , A , B , C , D , E , F , G > ( path ) ; export function defSetter < T , A , B , C , D , E , F , G , H > ( path ) ; export function defSetter < T , A , B , C , D , E , F , G , H > ( path ) ; export function defSetter ( path ) { const ks = toPath ( path ) ; const [ a , b , c , d ] = ks ; switch ( ks . length ) { case 0 : return ( _ , v ) => v ; case 1 : return ( s , v ) => ( ( s = copy ( s ) ) , ( s [ a ] = v ) , s ) ; case 2 : return ( s , v ) => { let x ; s = copy ( s ) ; s [ a ] = x = copy ( s [ a ] ) ; x [ b ] = v ; return s ; } ; case 3 : return ( s , v ) => { let x , y ; s = copy ( s ) ; s [ a ] = x = copy ( s [ a ] ) ; x [ b ] = y = copy ( x [ b ] ) ; y [ c ] = v ; return s ; } ; case 4 : return ( s , v ) => { let x , y , z ; s = copy ( s ) ; s [ a ] = x = copy ( s [ a ] ) ; x [ b ] = y = copy ( x [ b ] ) ; y [ c ] = z = copy ( y [ c ] ) ; z [ d ] = v ; return s ; } ; default : let f ; for ( let i = ks . length ; i -- > 0 ; ) { f = compS ( ks [ i ] , f ) ; } return f ; } } param x export const copy = ( x ) => isArray ( x ) || isTypedArray ( x ) ? x . slice ( ) : { ... x } ; /**
 * Helper for  defSetter . Returns setter for a single step.
 *
 *  param k param f internal const compS = ( k , f ) => ( s , v ) => { s = copy ( s ) ; s [ k ] = f ? f ( s [ k ] , v ) : v ; return s ; } ;