import type { DeepPath , Fn2 , Path , Path0 , Path1 , Path2 , Path3 , Path4 , Path5 , Path6 , Path7 , Path8 , PathVal , } from "@thi.ng/api" ; import { disallowProtoPath , toPath } from "./path.js" ; /**
 * Unchecked version of  defMutator .
 *
 *  remarks param path export const defMutatorUnsafe = < T = any > ( path ) : Fn2 < any , T , any > => defMutator ( < any > path ) ; /**
 * Higher-order function, similar to  defSetter . Returns a
 * function, which when called, mutates given object/array at given path
 * location.
 *
 *  remarks The returned function bails if any intermediate path values are
 * non-indexable (only the very last path element can be missing in the
 * actual object structure). If successful, returns original (mutated)
 * object, else `undefined`. This function provides optimized versions
 * for path lengths <= 4.
 *
 * Only the first 8 path levels are type checked.
 *
 * Also see  defMutatorUnsafe ,  mutIn param path export function defMutator < T > ( path ) ; export function defMutator < T , A > ( path ) ; export function defMutator < T , A , B > ( path ) ; export function defMutator < T , A , B , C > ( path ) ; export function defMutator < T , A , B , C , D > ( path ) ; export function defMutator < T , A , B , C , D , E > ( path ) ; export function defMutator < T , A , B , C , D , E , F > ( path ) ; export function defMutator < T , A , B , C , D , E , F , G > ( path ) ; export function defMutator < T , A , B , C , D , E , F , G , H > ( path ) ; export function defMutator < T , A , B , C , D , E , F , G , H > ( path ) ; export function defMutator ( path ) { const ks = toPath ( path ) ; disallowProtoPath ( ks ) ; let [ a , b , c , d ] = ks ; switch ( ks . length ) { case 0 : return ( _ , x ) => x ; case 1 : return ( s , x ) => ( s ? ( ( s [ a ] = x ) , s ) : undefined ) ; case 2 : return ( s , x ) => { let t ; return s ? ( t = s [ a ] ) ? ( ( t [ b ] = x ) , s ) : undefined : undefined ; } ; case 3 : return ( s , x ) => { let t ; return s ? ( t = s [ a ] ) ? ( t = t [ b ] ) ? ( ( t [ c ] = x ) , s ) : undefined : undefined : undefined ; } ; case 4 : return ( s , x ) => { let t ; return s ? ( t = s [ a ] ) ? ( t = t [ b ] ) ? ( t = t [ c ] ) ? ( ( t [ d ] = x ) , s ) : undefined : undefined : undefined : undefined ; } ; default : return ( s , x ) => { let t = s ; const n = ks . length - 1 ; for ( let k = 0 ; k < n ; k ++ ) { if ( ! ( t = t [ ks [ k ] ] ) ) return ; } t [ ks [ n ] ] = x ; return s ; } ; } }