import type { Fn } from "@thi.ng/api" ; import { isIterable } from "@thi.ng/checks/is-iterable" ; import type { Transducer } from "./api.js" ; import { comp } from "./comp.js" ; import { iterator } from "./iterator.js" ; import { mapKeys } from "./map-keys.js" ; import { partition } from "./partition.js" ; import { partitionOf } from "./partition-of.js" ; import { rename } from "./rename.js" ; export interface StructField extends Array < any > { [ 0 ] : string ; [ 1 ] : number ; [ 2 ] ? : Fn < any [ ] , any > ; } remarks example param fields param src export function struct < T > ( fields ) ; export function struct < T > ( fields , src ) ; export function struct ( fields , src ? ) { return isIterable ( src ) ? iterator ( struct ( fields ) , src ) : comp ( partitionOf ( fields . map ( ( f ) => f [ 1 ] ) ) , partition ( fields . length ) , rename ( fields . map ( ( f ) => f [ 0 ] ) ) , mapKeys ( fields . reduce ( ( acc , f ) => ( f [ 2 ] ? ( ( acc [ f [ 0 ] ] = f [ 2 ] ) , acc ) : acc ) , { } ) , false ) ) ; }