import type { FnAny } from "@thi.ng/api" ; import { illegalArity } from "@thi.ng/errors/illegal-arity" ; import type { IReducible , Reducer , Transducer , TxLike } from "./api.js" ; import { ensureTransducer } from "./ensure.js" ; import { map } from "./map.js" ; import { reduce , reduceRight } from "./reduce.js" ; export function transduce < A , B , C > ( tx , rfn ) ; export function transduce < A , B , C > ( tx , rfn , xs ) ; export function transduce < A , B , C > ( tx , rfn , xs ) ; export function transduce < A , B , C > ( tx , rfn , acc , xs ) ; export function transduce < A , B , C > ( tx , rfn , acc , xs ) ; export function transduce ( ... args ) { return $transduce ( transduce , reduce , args ) ; } export function transduceRight < A , B , C > ( tx , rfn ) ; export function transduceRight < A , B , C > ( tx , rfn , xs ) ; export function transduceRight < A , B , C > ( tx , rfn , acc , xs ) ; export function transduceRight ( ... args ) { return $transduce ( transduceRight , reduceRight , args ) ; } const $transduce = ( tfn , rfn , args ) => { let acc , xs ; switch ( args . length ) { case 4 : xs = args [ 3 ] ; acc = args [ 2 ] ; break ; case 3 : xs = args [ 2 ] ; break ; case 2 : return map ( ( x ) => tfn ( args [ 0 ] , args [ 1 ] , x ) ) ; default : illegalArity ( args . length ) ; } return rfn ( ensureTransducer ( args [ 0 ] ) ( args [ 1 ] ) , acc , xs ) ; } ;