// ets_tracing: off import { identity, pipe } from "../../Function/index.js" import type { Covariant, CovariantComposition } from "../Covariant/index.js" import { getCovariantComposition } from "../Covariant/index.js" import * as HKT from "../HKT/index.js" import type { IdentityBoth } from "../IdentityBoth/index.js" export interface ForeachFn { (G: IdentityBoth & Covariant): < GK, GQ, GW, GX, GI, GS, GR, GE, A, B >( f: (a: A) => HKT.Kind ) => ( fa: HKT.Kind ) => HKT.Kind< G, GC, GK, GQ, GW, GX, GI, GS, GR, GE, HKT.Kind > } export interface ForeachFn_ { ( fa: HKT.Kind, G: IdentityBoth & Covariant ): ( f: (a: A) => HKT.Kind ) => HKT.Kind< G, GC, GK, GQ, GW, GX, GI, GS, GR, GE, HKT.Kind > } export interface ForEach extends HKT.Base, Covariant { readonly _ForEach: "ForEach" readonly forEachF: ForeachFn } export function implementForEachF(): ( i: (_: { A: A B: B G: G N: N K: K SI: SI SO: SO X: X I: I S: S R: R E: E }) => ( G: IdentityBoth> & Covariant> ) => ( f: (a: A) => HKT.HKT ) => ( fa: HKT.Kind ) => HKT.HKT> ) => ForeachFn export function implementForEachF() { return (i: any) => i() } export interface ForEachCompositionFn< F extends HKT.URIS, G extends HKT.URIS, CF = HKT.Auto, CG = HKT.Auto > { (H: IdentityBoth & Covariant): < HK, HQ, HW, HX, HI, HS, HR, HE, A, B >( f: (a: A) => HKT.Kind ) => ( fa: HKT.Kind< F, CF, FK, FQ, FW, FX, FI, FS, FR, FE, HKT.Kind > ) => HKT.Kind< H, CH, HK, HQ, HW, HX, HI, HS, HR, HE, HKT.Kind< F, CF, FK, FQ, FW, FX, FI, FS, FR, FE, HKT.Kind > > } export interface ForEachComposition< F extends HKT.URIS, G extends HKT.URIS, CF = HKT.Auto, CG = HKT.Auto > extends HKT.CompositionBase2, CovariantComposition { readonly _ForEachComposition: "ForEachComposition" readonly forEachF: ForEachCompositionFn } export function getForEachComposition< F extends HKT.URIS, G extends HKT.URIS, CF = HKT.Auto, CG = HKT.Auto >(F: ForEach, G: ForEach): ForEachComposition export function getForEachComposition( F: ForEach>, G: ForEach> ) { return HKT.instance, HKT.UHKT>>({ ...getCovariantComposition(F, G), forEachF: (H) => (f) => pipe(f, G.forEachF(H), F.forEachF(H)) }) } export function sequenceF( T: ForEach ): ( App: Covariant & IdentityBoth ) => ( _: HKT.Kind< T, C, K, Q, W, X, I, S, R, E, HKT.Kind > ) => HKT.Kind< F, FC, FK, FQ, FW, FX, FI, FS, FR, FE, HKT.Kind > export function sequenceF( T: ForEach> ): ( App: Covariant> & IdentityBoth> ) => (_: HKT.HKT>) => HKT.HKT> { return (App) => { const traverse = T.forEachF(App) return traverse(identity) } }