import type { DeepPath , Fn , OptPathVal , Path , Path0 , Path1 , Path2 , Path3 , Path4 , Path5 , Path6 , Path7 , Path8 , } from "@thi.ng/api" ; import { toPath } from "./path.js" ; /**
 * Unchecked version of  defGetter .
 *
 *  remarks The type parameter `T` can be used to indicate the type of the nested
 * value to be retrieved (default: `any`).
 *
 * Also see:  getIn ,  getInUnsafe example param path export const defGetterUnsafe = < T = any > ( path ) : Fn < any , T | undefined > => defGetter ( < any > path ) ; remarks Optimized fast execution paths are provided for path lengths <= 4.
 * Only the first 8 path levels are type checked.
 *
 * Supports any `[]`-indexable data structure (arrays, objects,
 * strings).
 *
 * If any intermediate key is not present in the given obj, further
 * descent stops and the function returns `undefined`.
 *
 * If `path` is an empty array, the returned getter will simply return
 * the given state arg (aka identity function).
 *
 * Also see:  defGetterUnsafe ,  getIn ,  getInUnsafe example param path export function defGetter < T > ( path ) ; export function defGetter < T , A > ( path ) ; export function defGetter < T , A , B > ( path ) ; export function defGetter < T , A , B , C > ( path ) ; export function defGetter < T , A , B , C , D > ( path ) ; export function defGetter < T , A , B , C , D , E > ( path ) ; export function defGetter < T , A , B , C , D , E , F > ( path ) ; export function defGetter < T , A , B , C , D , E , F , G > ( path ) ; export function defGetter < T , A , B , C , D , E , F , G , H > ( path ) ; export function defGetter < T , A , B , C , D , E , F , G , H > ( path ) ; export function defGetter ( path ) { const ks = toPath ( path ) ; const [ a , b , c , d ] = ks ; switch ( ks . length ) { case 0 : return ( s ) => s ; case 1 : return ( s ) => ( s != null ? s [ a ] : undefined ) ; case 2 : return ( s ) => s != null ? ( ( s = s [ a ] ) != null ? s [ b ] : undefined ) : undefined ; case 3 : return ( s ) => s != null ? ( s = s [ a ] ) != null ? ( s = s [ b ] ) != null ? s [ c ] : undefined : undefined : undefined ; case 4 : return ( s ) => s != null ? ( s = s [ a ] ) != null ? ( s = s [ b ] ) != null ? ( s = s [ c ] ) != null ? s [ d ] : undefined : undefined : undefined : undefined ; default : return ( s ) => { const n = ks . length - 1 ; let res = s ; for ( let i = 0 ; res != null && i <= n ; i ++ ) { res = res [ ks [ i ] ] ; } return res ; } ; } }