import { isFunction } from "@thi.ng/checks/is-function" ; import type { TransformSpec } from "./api.js" ; /**
 * Higher-order deep object transformer used by  {@link (mapDeep:1)} .
 * Accepts a nested `spec` array reflecting same key structure as the
 * object to be mapped, but with functions or sub-specs as their values.
 * Returns a new function, which when called, recursively applies nested
 * transformers in post-order traversal (child transformers are run
 * first) and returns the result of the root transformer.
 *
 *  remarks example param spec export const deepTransform = ( spec ) : ( ( x : any ) => any ) => { if ( isFunction ( spec ) ) { return < any > spec ; } const mapfns = Object . keys ( spec [ 1 ] || { } ) . reduce ( ( acc , k ) => ( ( acc [ k ] = deepTransform ( ( < any > spec ) [ 1 ] [ k ] ) ) , acc ) , { } ) ; return ( x ) => { const res = { ... x } ; for ( let k in mapfns ) { res [ k ] = mapfns [ k ] ( res [ k ] ) ; } return spec [ 0 ] ( res ) ; } ; } ;