import {
  getFoldableComposition
} from "./chunk-NRCL53NI.mjs";
import {
  pipe
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/FoldableWithIndex.ts
var FoldableWithIndex_exports = {};
__export(FoldableWithIndex_exports, {
  foldMapWithIndex: () => foldMapWithIndex,
  getFoldableWithIndexComposition: () => getFoldableWithIndexComposition,
  reduceRightWithIndex: () => reduceRightWithIndex,
  reduceWithIndex: () => reduceWithIndex
});
function reduceWithIndex(F, G) {
  return (b, f) => (fga) => F.reduceWithIndex(fga, b, (i, b2, ga) => G.reduceWithIndex(ga, b2, (j, b3, a) => f([i, j], b3, a)));
}
function foldMapWithIndex(F, G) {
  return (M) => {
    const foldMapWithIndexF = F.foldMapWithIndex(M);
    const foldMapWithIndexG = G.foldMapWithIndex(M);
    return (f) => (fga) => foldMapWithIndexF(fga, (i, ga) => foldMapWithIndexG(ga, (j, a) => f([i, j], a)));
  };
}
function reduceRightWithIndex(F, G) {
  return (b, f) => (fga) => F.reduceRightWithIndex(fga, b, (i, ga, b2) => G.reduceRightWithIndex(ga, b2, (j, a, b3) => f([i, j], a, b3)));
}
function getFoldableWithIndexComposition(F, G) {
  const FC = getFoldableComposition(F, G);
  const _reduceWithIndex = reduceWithIndex(F, G);
  const _foldMapWithIndex = foldMapWithIndex(F, G);
  const _reduceRightWithIndex = reduceRightWithIndex(F, G);
  return {
    reduce: FC.reduce,
    foldMap: FC.foldMap,
    reduceRight: FC.reduceRight,
    reduceWithIndex: (fga, b, f) => pipe(fga, _reduceWithIndex(b, f)),
    foldMapWithIndex: (M) => {
      const foldMapWithIndexM = _foldMapWithIndex(M);
      return (fga, f) => pipe(fga, foldMapWithIndexM(f));
    },
    reduceRightWithIndex: (fga, b, f) => pipe(fga, _reduceRightWithIndex(b, f))
  };
}

export {
  reduceWithIndex,
  foldMapWithIndex,
  reduceRightWithIndex,
  getFoldableWithIndexComposition,
  FoldableWithIndex_exports
};
