import { List } from "../../list"; import { NoInfer, Satisfies, Unreachable } from "../../type"; import { $, HKT, _, I } from ".."; declare const TS_TYPE_ERROR: unique symbol; type TS_TYPE_ERROR = { [TS_TYPE_ERROR]: Message; }; type ValidateAccumulatorHkt = [ F ] extends [HKT<[any, any], any>] ? [F] extends [HKT<[infer A, infer B], NoInfer>] ? HKT<[A, B], A> : TS_TYPE_ERROR<'Accumulator HKT output must be assignable to input accumulated value'> : TS_TYPE_ERROR<'expected HKT of the form (A, B) => A'>; type __$Fold2, L extends List, A, Acc extends A> = L extends readonly [infer H, ...infer T] ? __$Fold2> : Acc; /** * folds over `L` with function `F` and initial value `Initial`. * * @warning you probably want to use `$Fold` instead. */ type _$Fold2, Initial extends A, L extends List, A> = __$Fold2; /** * folds over `L` with function `F` and initial value `Initial`. * * @since 0.0.5 */ export type $Fold, Initial extends (F extends HKT<[infer A, any], NoInfer> ? A : Unreachable), L extends (F extends HKT<[infer A, infer B], NoInfer> ? List : Unreachable)> = F extends HKT<[infer A, infer B], NoInfer> ? Initial extends A ? L extends List ? _$Fold2 : Unreachable : Unreachable : Unreachable; /** * @since 0.0.5 * * @todo how to add custom constraints to hkt input? (e.g. ensure only nonvariadics passed in to $ and error if not) * @todo any way to clean up / reduce redundancy in the code to for custom typechecks here? * @todo curry this so can pass initial as separate hkt, this will make it more composable */ export interface Fold, Initial extends (F extends HKT<[infer A, any], NoInfer> ? A : Unreachable)> extends HKT { [HKT.i]: Satisfies<_, List> ? B : any>>; [HKT.o]: F extends HKT<[infer A, infer B], NoInfer> ? Initial extends A ? I extends List ? _$Fold2, A> : Unreachable : Unreachable : Unreachable; } export {}; //# sourceMappingURL=fold.d.ts.map