import type { Applicative } from './Applicative' import type { FunctorWithIndexMin } from './FunctorWithIndex' import { FunctorWithIndex } from './FunctorWithIndex' import * as HKT from './HKT' export interface TraversableWithIndex extends FunctorWithIndex { readonly itraverse_: TraverseWithIndexFn_ readonly itraverse: TraverseWithIndexFn } export type TraversableWithIndexMin = FunctorWithIndexMin & { readonly itraverse_: TraverseWithIndexFn_ } export function TraversableWithIndex( F: TraversableWithIndexMin ): TraversableWithIndex { return HKT.instance({ ...FunctorWithIndex(F), itraverse_: F.itraverse_, itraverse: (A) => { const itraverseA_ = F.itraverse_(A) return (f) => (ta) => itraverseA_(ta, f) } }) } export interface TraverseWithIndexFn { (A: Applicative): < NG extends string, KG, QG, WG, XG, IG, SG, RG, EG, NF extends string, KF, A, B >( f: ( i: HKT.IndexFor, HKT.OrFix<'K', CF, KF>>, a: A ) => HKT.Kind ) => ( ta: HKT.Kind ) => HKT.Kind> } export interface TraverseWithIndexFn_ { (A: Applicative): < NG extends string, KG, QG, WG, XG, IG, SG, RG, EG, NF extends string, KF, QF, WF, XF, IF, SF, RF, EF, A, B >( ta: HKT.Kind, f: ( i: HKT.IndexFor, HKT.OrFix<'K', CF, KF>>, a: A ) => HKT.Kind ) => HKT.Kind> } export interface TraverseWithIndexFnComposition { (A: Applicative): < FN extends string, FK, GN extends string, GK, HN extends string, HK, HQ, HW, HX, HI, HS, HR, HE, A, B >( f: ( i: [ HKT.IndexFor, HKT.OrFix<'K', CF, FK>>, HKT.IndexFor, HKT.OrFix<'K', CG, GK>> ], a: A ) => HKT.Kind ) => ( fga: HKT.Kind> ) => HKT.Kind< H, CH, HN, HK, HQ, HW, HX, HI, HS, HR, HE, HKT.Kind> > } export interface TraverseWithIndexFnComposition_ { (A: Applicative): < FN extends string, FK, FQ, FW, FX, FI, FS, FR, FE, GN extends string, GK, GQ, GW, GX, GI, GS, GR, GE, HN extends string, HK, HQ, HW, HX, HI, HS, HR, HE, A, B >( fga: HKT.Kind>, f: ( i: [ HKT.IndexFor, HKT.OrFix<'K', CF, FK>>, HKT.IndexFor, HKT.OrFix<'K', CG, GK>> ], a: A ) => HKT.Kind ) => HKT.Kind< H, CH, HN, HK, HQ, HW, HX, HI, HS, HR, HE, HKT.Kind> > } export function implementTraverseWithIndex(): ( i: (_: { A: A B: B G: G N: N K: K Q: Q W: W X: X I: I S: S R: R E: E }) => ( A: Applicative> ) => ( f: (i: HKT.IndexFor, HKT.OrFix<'K', C, K>>, a: A) => HKT.HKT ) => (ta: HKT.Kind) => HKT.HKT> ) => TraverseWithIndexFn export function implementTraverseWithIndex() { return (i: any) => i() } export function implementTraverseWithIndex_(): ( i: (_: { A: A B: B G: G N: N K: HKT.OrFix<'K', C, K> Q: Q W: W X: X I: I S: S R: R E: HKT.OrFix<'E', C, E> }) => ( G: Applicative> ) => ( ta: HKT.Kind, f: (i: HKT.IndexFor, HKT.OrFix<'K', C, K>>, a: A) => HKT.HKT ) => HKT.HKT> ) => TraverseWithIndexFn_ export function implementTraverseWithIndex_() { return (i: any) => i() }