import {
  createArrowFn,
  createIIFE
} from "./chunk-RZHX2YRY.js";
import {
  getParCombineBuilderFromRegistry,
  registerInstanceWithMeta,
  registerParCombineBuilder
} from "./chunk-4QIJY5PM.js";

// src/typeclasses/par-combine.ts
import * as ts from "typescript";
import { createGenericRegistry } from "@typesugar/core";
var parCombinePromise = {
  all: (effects) => Promise.all(effects),
  map: (combined, f) => combined.then(f)
};
async function collectAsync(iter) {
  const result = [];
  for await (const item of iter)
    result.push(item);
  return result;
}
var parCombineAsyncIterable = {
  all: (effects) => Promise.all(effects.map((e) => collectAsync(e))),
  map: (combined, f) => combined.then(f)
};
function cartesianProduct(arrays) {
  return arrays.reduce((acc, arr) => acc.flatMap((combo) => arr.map((item) => [...combo, item])), [[]]);
}
var parCombineArray = {
  all: (effects) => cartesianProduct(effects),
  map: (combined, f) => combined.map(f)
};
var parCombineIterable = {
  all: (effects) => {
    const arrays = effects.map((it) => Array.from(it));
    return cartesianProduct(arrays);
  },
  map: (combined, f) => combined.map(f)
};
var parCombineRegistry = createGenericRegistry({
  name: "ParCombineRegistry",
  duplicateStrategy: "replace"
});
function registerBuiltin(name, instance, builder) {
  parCombineRegistry.set(name, { instance, builder });
}
registerBuiltin("Promise", parCombinePromise, buildPromiseAll);
registerBuiltin("AsyncIterable", parCombineAsyncIterable, buildAsyncIterableAll);
registerBuiltin("Array", parCombineArray, buildArrayParCombine);
registerBuiltin("Iterable", parCombineIterable, buildIterableParCombine);
function registerInUnifiedRegistry(name) {
  registerInstanceWithMeta({
    typeclassName: "ParCombine",
    forType: name,
    instanceName: `parCombine${name}`,
    derived: false,
    meta: {
      builderName: name
      // Reference to builder in parCombineBuilderRegistry
    }
  });
}
registerInUnifiedRegistry("Promise");
registerInUnifiedRegistry("AsyncIterable");
registerInUnifiedRegistry("Array");
registerInUnifiedRegistry("Iterable");
registerParCombineBuilder("Promise", buildPromiseAll);
registerParCombineBuilder("AsyncIterable", buildAsyncIterableAll);
registerParCombineBuilder("Array", buildArrayParCombine);
registerParCombineBuilder("Iterable", buildIterableParCombine);
function getParCombine(name) {
  return parCombineRegistry.get(name)?.instance;
}
function getParCombineBuilder(name) {
  const unifiedBuilder = getParCombineBuilderFromRegistry(name);
  if (unifiedBuilder) {
    return unifiedBuilder;
  }
  return parCombineRegistry.get(name)?.builder;
}
function registerParCombine(name, instance, builder) {
  const actualBuilder = builder ?? createGenericParCombineBuilder(name);
  parCombineRegistry.set(name, {
    instance,
    builder: actualBuilder
  });
  registerInUnifiedRegistry(name);
  registerParCombineBuilder(name, actualBuilder);
}
function buildPromiseAll(ctx, steps, returnExpr) {
  const { factory } = ctx;
  const bindSteps = steps.filter((s) => s.kind === "bind");
  const mapSteps = steps.filter((s) => s.kind === "map");
  let yieldExpr = returnExpr;
  for (let i = mapSteps.length - 1; i >= 0; i--) {
    const step = mapSteps[i];
    yieldExpr = createIIFE(factory, step.name, yieldExpr, step.expression);
  }
  if (bindSteps.length === 0)
    return yieldExpr;
  if (bindSteps.length === 1) {
    return factory.createCallExpression(factory.createPropertyAccessExpression(bindSteps[0].effect, factory.createIdentifier("then")), void 0, [createArrowFn(factory, bindSteps[0].name, yieldExpr)]);
  }
  const allCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Promise"), factory.createIdentifier("all")), void 0, [factory.createArrayLiteralExpression(bindSteps.map((s) => s.effect))]);
  const destructuredParam = factory.createParameterDeclaration(void 0, void 0, factory.createArrayBindingPattern(bindSteps.map((s) => factory.createBindingElement(void 0, void 0, factory.createIdentifier(s.name)))));
  return factory.createCallExpression(factory.createPropertyAccessExpression(allCall, factory.createIdentifier("then")), void 0, [
    factory.createArrowFunction(void 0, void 0, [destructuredParam], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), yieldExpr)
  ]);
}
function buildAsyncIterableAll(ctx, steps, returnExpr) {
  const { factory } = ctx;
  const bindSteps = steps.filter((s) => s.kind === "bind");
  const mapSteps = steps.filter((s) => s.kind === "map");
  let yieldExpr = returnExpr;
  for (let i = mapSteps.length - 1; i >= 0; i--) {
    const step = mapSteps[i];
    yieldExpr = createIIFE(factory, step.name, yieldExpr, step.expression);
  }
  if (bindSteps.length === 0)
    return yieldExpr;
  const createCollectAsync = (expr) => {
    const iterParam = factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("__iter"));
    const resultVar = factory.createVariableDeclaration(factory.createIdentifier("__r"), void 0, void 0, factory.createArrayLiteralExpression([]));
    const forOfStmt = factory.createForOfStatement(factory.createToken(ts.SyntaxKind.AwaitKeyword), factory.createVariableDeclarationList([
      factory.createVariableDeclaration(factory.createIdentifier("__x"), void 0, void 0, void 0)
    ], ts.NodeFlags.Const), factory.createIdentifier("__iter"), factory.createBlock([
      factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__r"), factory.createIdentifier("push")), void 0, [factory.createIdentifier("__x")]))
    ]));
    const returnStmt = factory.createReturnStatement(factory.createIdentifier("__r"));
    const block = factory.createBlock([
      factory.createVariableStatement(void 0, factory.createVariableDeclarationList([resultVar], ts.NodeFlags.Const)),
      forOfStmt,
      returnStmt
    ], true);
    const asyncArrow = factory.createArrowFunction([factory.createToken(ts.SyntaxKind.AsyncKeyword)], void 0, [iterParam], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), block);
    return factory.createCallExpression(factory.createParenthesizedExpression(asyncArrow), void 0, [expr]);
  };
  if (bindSteps.length === 1) {
    const collected = createCollectAsync(bindSteps[0].effect);
    return factory.createCallExpression(factory.createPropertyAccessExpression(collected, factory.createIdentifier("then")), void 0, [createArrowFn(factory, bindSteps[0].name, yieldExpr)]);
  }
  const allCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Promise"), factory.createIdentifier("all")), void 0, [factory.createArrayLiteralExpression(bindSteps.map((s) => createCollectAsync(s.effect)))]);
  const destructuredParam = factory.createParameterDeclaration(void 0, void 0, factory.createArrayBindingPattern(bindSteps.map((s) => factory.createBindingElement(void 0, void 0, factory.createIdentifier(s.name)))));
  return factory.createCallExpression(factory.createPropertyAccessExpression(allCall, factory.createIdentifier("then")), void 0, [
    factory.createArrowFunction(void 0, void 0, [destructuredParam], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), yieldExpr)
  ]);
}
function buildArrayParCombine(ctx, steps, returnExpr) {
  const { factory } = ctx;
  const bindSteps = steps.filter((s) => s.kind === "bind");
  const mapSteps = steps.filter((s) => s.kind === "map");
  let yieldExpr = returnExpr;
  for (let i = mapSteps.length - 1; i >= 0; i--) {
    const step = mapSteps[i];
    yieldExpr = createIIFE(factory, step.name, yieldExpr, step.expression);
  }
  if (bindSteps.length === 0)
    return yieldExpr;
  if (bindSteps.length === 1) {
    return factory.createCallExpression(factory.createPropertyAccessExpression(bindSteps[0].effect, factory.createIdentifier("map")), void 0, [createArrowFn(factory, bindSteps[0].name, yieldExpr)]);
  }
  const effectsArray = factory.createArrayLiteralExpression(bindSteps.map((s) => s.effect));
  const spreadComboAndItem = factory.createArrayLiteralExpression([
    factory.createSpreadElement(factory.createIdentifier("combo")),
    factory.createIdentifier("item")
  ]);
  const reduceCallback = factory.createArrowFunction(void 0, void 0, [
    factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("acc")),
    factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("arr"))
  ], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("acc"), factory.createIdentifier("flatMap")), void 0, [
    factory.createArrowFunction(void 0, void 0, [
      factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("combo"))
    ], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("arr"), factory.createIdentifier("map")), void 0, [
      factory.createArrowFunction(void 0, void 0, [
        factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("item"))
      ], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), spreadComboAndItem)
    ]))
  ]));
  const reduceCall = factory.createCallExpression(factory.createPropertyAccessExpression(effectsArray, factory.createIdentifier("reduce")), void 0, [
    reduceCallback,
    factory.createArrayLiteralExpression([factory.createArrayLiteralExpression([])])
  ]);
  const destructuredParam = factory.createParameterDeclaration(void 0, void 0, factory.createArrayBindingPattern(bindSteps.map((s) => factory.createBindingElement(void 0, void 0, factory.createIdentifier(s.name)))));
  return factory.createCallExpression(factory.createPropertyAccessExpression(reduceCall, factory.createIdentifier("map")), void 0, [
    factory.createArrowFunction(void 0, void 0, [destructuredParam], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), yieldExpr)
  ]);
}
function buildIterableParCombine(ctx, steps, returnExpr) {
  const { factory } = ctx;
  const bindSteps = steps.filter((s) => s.kind === "bind");
  const mapSteps = steps.filter((s) => s.kind === "map");
  let yieldExpr = returnExpr;
  for (let i = mapSteps.length - 1; i >= 0; i--) {
    const step = mapSteps[i];
    yieldExpr = createIIFE(factory, step.name, yieldExpr, step.expression);
  }
  if (bindSteps.length === 0)
    return yieldExpr;
  const arraysExpr = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createArrayLiteralExpression(bindSteps.map((s) => s.effect)), factory.createIdentifier("map")), void 0, [
    factory.createArrowFunction(void 0, void 0, [factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("it"))], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Array"), factory.createIdentifier("from")), void 0, [factory.createIdentifier("it")]))
  ]);
  if (bindSteps.length === 1) {
    return factory.createCallExpression(factory.createPropertyAccessExpression(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Array"), factory.createIdentifier("from")), void 0, [bindSteps[0].effect]), factory.createIdentifier("map")), void 0, [createArrowFn(factory, bindSteps[0].name, yieldExpr)]);
  }
  const spreadComboAndItem = factory.createArrayLiteralExpression([
    factory.createSpreadElement(factory.createIdentifier("combo")),
    factory.createIdentifier("item")
  ]);
  const reduceCallback = factory.createArrowFunction(void 0, void 0, [
    factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("acc")),
    factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("arr"))
  ], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("acc"), factory.createIdentifier("flatMap")), void 0, [
    factory.createArrowFunction(void 0, void 0, [
      factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("combo"))
    ], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("arr"), factory.createIdentifier("map")), void 0, [
      factory.createArrowFunction(void 0, void 0, [
        factory.createParameterDeclaration(void 0, void 0, factory.createIdentifier("item"))
      ], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), spreadComboAndItem)
    ]))
  ]));
  const reduceCall = factory.createCallExpression(factory.createPropertyAccessExpression(arraysExpr, factory.createIdentifier("reduce")), void 0, [
    reduceCallback,
    factory.createArrayLiteralExpression([factory.createArrayLiteralExpression([])])
  ]);
  const destructuredParam = factory.createParameterDeclaration(void 0, void 0, factory.createArrayBindingPattern(bindSteps.map((s) => factory.createBindingElement(void 0, void 0, factory.createIdentifier(s.name)))));
  return factory.createCallExpression(factory.createPropertyAccessExpression(reduceCall, factory.createIdentifier("map")), void 0, [
    factory.createArrowFunction(void 0, void 0, [destructuredParam], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), yieldExpr)
  ]);
}
function createGenericParCombineBuilder(name) {
  return (ctx, steps, returnExpr) => {
    const { factory } = ctx;
    const bindSteps = steps.filter((s) => s.kind === "bind");
    const mapSteps = steps.filter((s) => s.kind === "map");
    let yieldExpr = returnExpr;
    for (let i = mapSteps.length - 1; i >= 0; i--) {
      const step = mapSteps[i];
      yieldExpr = createIIFE(factory, step.name, yieldExpr, step.expression);
    }
    if (bindSteps.length === 0)
      return yieldExpr;
    const nameLiteral = factory.createStringLiteral(name);
    const effectsArray = factory.createArrayLiteralExpression(bindSteps.map((s) => s.effect));
    const destructuredParam = factory.createParameterDeclaration(void 0, void 0, factory.createArrayBindingPattern(bindSteps.map((s) => factory.createBindingElement(void 0, void 0, factory.createIdentifier(s.name)))));
    const mapArrow = factory.createArrowFunction(void 0, void 0, [destructuredParam], void 0, factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), yieldExpr);
    const pcDecl = factory.createVariableDeclaration(factory.createIdentifier("__pc"), void 0, void 0, factory.createNonNullExpression(factory.createCallExpression(factory.createIdentifier("getParCombine"), void 0, [
      nameLiteral
    ])));
    const allCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__pc"), factory.createIdentifier("all")), void 0, [effectsArray]);
    const mapCall = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("__pc"), factory.createIdentifier("map")), void 0, [allCall, mapArrow]);
    const returnStmt = factory.createReturnStatement(mapCall);
    const block = factory.createBlock([
      factory.createVariableStatement(void 0, factory.createVariableDeclarationList([pcDecl], ts.NodeFlags.Const)),
      returnStmt
    ], true);
    const iife = factory.createCallExpression(factory.createParenthesizedExpression(factory.createArrowFunction(void 0, void 0, [], void 0, void 0, block)), void 0, []);
    return iife;
  };
}

// src/typeclasses/numeric-ops.ts
function sum(xs, N) {
  let acc = N.zero();
  for (const x of xs) {
    acc = N.add(acc, x);
  }
  return acc;
}
function product(xs, N) {
  let acc = N.one();
  for (const x of xs) {
    acc = N.mul(acc, x);
  }
  return acc;
}
function pow(base, exp, N) {
  if (exp < 0) {
    throw new RangeError("pow: exponent must be non-negative for Numeric types");
  }
  if (exp === 0)
    return N.one();
  if (exp === 1)
    return base;
  let result = N.one();
  let b = base;
  let e = exp;
  while (e > 0) {
    if (e & 1) {
      result = N.mul(result, b);
    }
    b = N.mul(b, b);
    e >>>= 1;
  }
  return result;
}
function powFrac(base, exp, N, F) {
  if (exp >= 0) {
    return pow(base, exp, N);
  }
  return F.recip(pow(base, -exp, N));
}
function gcdWith(a, b, N, I) {
  a = N.abs(a);
  b = N.abs(b);
  while (N.toNumber(b) !== 0) {
    const t = b;
    b = I.mod(a, b);
    a = t;
  }
  return a;
}
function lcmWith(a, b, N, I) {
  const aNum = N.toNumber(a);
  const bNum = N.toNumber(b);
  if (aNum === 0 || bNum === 0)
    return N.zero();
  const g = gcdWith(a, b, N, I);
  return N.abs(I.div(N.mul(a, b), g));
}
function clampWith(x, lo, hi, O) {
  if (O.compare(x, lo) < 0)
    return lo;
  if (O.compare(x, hi) > 0)
    return hi;
  return x;
}
function min(a, b, O) {
  return O.compare(a, b) <= 0 ? a : b;
}
function max(a, b, O) {
  return O.compare(a, b) >= 0 ? a : b;
}
function minBy(xs, O) {
  let result;
  let first = true;
  for (const x of xs) {
    if (first) {
      result = x;
      first = false;
    } else if (O.compare(x, result) < 0) {
      result = x;
    }
  }
  if (first)
    throw new Error("minBy: empty iterable");
  return result;
}
function maxBy(xs, O) {
  let result;
  let first = true;
  for (const x of xs) {
    if (first) {
      result = x;
      first = false;
    } else if (O.compare(x, result) > 0) {
      result = x;
    }
  }
  if (first)
    throw new Error("maxBy: empty iterable");
  return result;
}
function lerpWith(a, b, t, N, F) {
  return N.add(a, N.mul(t, N.sub(b, a)));
}
function inverseLerpWith(a, b, value, N, F) {
  return F.div(N.sub(value, a), N.sub(b, a));
}
function fromInteger(n, N) {
  return N.fromNumber(Number(n));
}
function fromInt(n, N) {
  return N.fromNumber(n);
}

// src/typeclasses/index.ts
var eqNumber = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b
};
var eqBigInt = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b
};
var eqString = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b
};
var eqBoolean = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b
};
var eqDate = {
  equals: (a, b) => a.getTime() === b.getTime(),
  notEquals: (a, b) => a.getTime() !== b.getTime()
};
function makeEq(eq) {
  return {
    equals: eq,
    notEquals: ((a, b) => !eq(a, b))
  };
}
function eqBy(f, E = eqStrict()) {
  return {
    equals: ((a, b) => E.equals(f(a), f(b))),
    notEquals: ((a, b) => E.notEquals(f(a), f(b)))
  };
}
function eqStrict() {
  return {
    equals: ((a, b) => a === b),
    notEquals: ((a, b) => a !== b)
  };
}
function eqArray(E) {
  return {
    equals: ((xs, ys) => {
      if (xs.length !== ys.length)
        return false;
      return xs.every((x, i) => E.equals(x, ys[i]));
    }),
    notEquals: ((xs, ys) => {
      if (xs.length !== ys.length)
        return true;
      return xs.some((x, i) => E.notEquals(x, ys[i]));
    })
  };
}
var LT = -1;
var EQ_ORD = 0;
var GT = 1;
var ordNumber = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b,
  compare: (a, b) => a < b ? LT : a > b ? GT : EQ_ORD,
  lessThan: (a, b) => a < b,
  lessThanOrEqual: (a, b) => a <= b,
  greaterThan: (a, b) => a > b,
  greaterThanOrEqual: (a, b) => a >= b
};
var ordBigInt = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b,
  compare: (a, b) => a < b ? LT : a > b ? GT : EQ_ORD,
  lessThan: (a, b) => a < b,
  lessThanOrEqual: (a, b) => a <= b,
  greaterThan: (a, b) => a > b,
  greaterThanOrEqual: (a, b) => a >= b
};
var ordString = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b,
  compare: (a, b) => a < b ? LT : a > b ? GT : EQ_ORD,
  lessThan: (a, b) => a < b,
  lessThanOrEqual: (a, b) => a <= b,
  greaterThan: (a, b) => a > b,
  greaterThanOrEqual: (a, b) => a >= b
};
var ordBoolean = {
  equals: (a, b) => a === b,
  notEquals: (a, b) => a !== b,
  compare: (a, b) => a === b ? EQ_ORD : a ? GT : LT,
  lessThan: (a, b) => !a && b,
  lessThanOrEqual: (a, b) => !a || b,
  greaterThan: (a, b) => a && !b,
  greaterThanOrEqual: (a, b) => a || !b
};
var ordDate = {
  equals: (a, b) => a.getTime() === b.getTime(),
  notEquals: (a, b) => a.getTime() !== b.getTime(),
  compare: (a, b) => {
    const ta = a.getTime();
    const tb = b.getTime();
    return ta < tb ? LT : ta > tb ? GT : EQ_ORD;
  },
  lessThan: (a, b) => a.getTime() < b.getTime(),
  lessThanOrEqual: (a, b) => a.getTime() <= b.getTime(),
  greaterThan: (a, b) => a.getTime() > b.getTime(),
  greaterThanOrEqual: (a, b) => a.getTime() >= b.getTime()
};
function makeOrd(compare) {
  return {
    equals: ((a, b) => compare(a, b) === EQ_ORD),
    notEquals: ((a, b) => compare(a, b) !== EQ_ORD),
    compare,
    lessThan: ((a, b) => compare(a, b) === LT),
    lessThanOrEqual: ((a, b) => compare(a, b) !== GT),
    greaterThan: ((a, b) => compare(a, b) === GT),
    greaterThanOrEqual: ((a, b) => compare(a, b) !== LT)
  };
}
function ordBy(f, O) {
  return {
    equals: ((a, b) => O.equals(f(a), f(b))),
    notEquals: ((a, b) => O.notEquals(f(a), f(b))),
    compare: (a, b) => O.compare(f(a), f(b)),
    lessThan: ((a, b) => O.lessThan(f(a), f(b))),
    lessThanOrEqual: ((a, b) => O.lessThanOrEqual(f(a), f(b))),
    greaterThan: ((a, b) => O.greaterThan(f(a), f(b))),
    greaterThanOrEqual: ((a, b) => O.greaterThanOrEqual(f(a), f(b)))
  };
}
function reverseOrd(O) {
  return {
    equals: O.equals,
    notEquals: O.notEquals,
    compare: (a, b) => O.compare(b, a),
    lessThan: O.greaterThan,
    lessThanOrEqual: O.greaterThanOrEqual,
    greaterThan: O.lessThan,
    greaterThanOrEqual: O.lessThanOrEqual
  };
}
function ordArray(O) {
  const E = eqArray({ equals: O.equals, notEquals: O.notEquals });
  return {
    equals: E.equals,
    notEquals: E.notEquals,
    compare: (xs, ys) => {
      const len = Math.min(xs.length, ys.length);
      for (let i = 0; i < len; i++) {
        const cmp = O.compare(xs[i], ys[i]);
        if (cmp !== EQ_ORD)
          return cmp;
      }
      return xs.length < ys.length ? LT : xs.length > ys.length ? GT : EQ_ORD;
    },
    lessThan: ((xs, ys) => ordArray(O).compare(xs, ys) === LT),
    lessThanOrEqual: ((xs, ys) => ordArray(O).compare(xs, ys) !== GT),
    greaterThan: ((xs, ys) => ordArray(O).compare(xs, ys) === GT),
    greaterThanOrEqual: ((xs, ys) => ordArray(O).compare(xs, ys) !== LT)
  };
}
var semigroupString = {
  combine: (a, b) => a + b
};
var semigroupNumber = {
  combine: (a, b) => a + b
};
var semigroupBigInt = {
  combine: (a, b) => a + b
};
function semigroupArray() {
  return {
    combine: ((a, b) => [...a, ...b])
  };
}
var monoidString = {
  combine: (a, b) => a + b,
  empty: () => ""
};
var monoidNumber = {
  combine: (a, b) => a + b,
  empty: () => 0
};
var monoidBigInt = {
  combine: (a, b) => a + b,
  empty: () => 0n
};
function monoidArray() {
  return {
    combine: ((a, b) => [...a, ...b]),
    empty: () => []
  };
}
var boundedNumber = {
  minBound: () => Number.MIN_SAFE_INTEGER,
  maxBound: () => Number.MAX_SAFE_INTEGER
};
var boundedBigInt = {
  minBound: () => BigInt("-9007199254740991"),
  maxBound: () => BigInt("9007199254740991")
};
var boundedBoolean = {
  minBound: () => false,
  maxBound: () => true
};
var boundedString = {
  minBound: () => "",
  maxBound: () => "\uFFFF".repeat(256)
};
var enumNumber = {
  succ: (a) => a + 1,
  pred: (a) => a - 1,
  toEnum: (n) => n,
  fromEnum: (a) => a
};
var enumBoolean = {
  succ: (a) => !a,
  pred: (a) => !a,
  toEnum: (n) => n !== 0,
  fromEnum: (a) => a ? 1 : 0
};
var enumString = {
  succ: (a) => a.length === 0 ? "a" : a.slice(0, -1) + String.fromCharCode(a.charCodeAt(a.length - 1) + 1),
  pred: (a) => a.length === 0 ? "" : a.slice(0, -1) + String.fromCharCode(a.charCodeAt(a.length - 1) - 1),
  toEnum: (n) => String.fromCharCode(n),
  fromEnum: (a) => a.length > 0 ? a.charCodeAt(0) : 0
};
var numericNumber = {
  add: (a, b) => a + b,
  sub: (a, b) => a - b,
  mul: (a, b) => a * b,
  negate: (a) => -a,
  abs: (a) => Math.abs(a),
  signum: (a) => Math.sign(a),
  fromNumber: (n) => n,
  toNumber: (a) => a,
  zero: () => 0,
  one: () => 1
};
var numericBigInt = {
  add: (a, b) => a + b,
  sub: (a, b) => a - b,
  mul: (a, b) => a * b,
  negate: (a) => -a,
  abs: (a) => a < 0n ? -a : a,
  signum: (a) => a < 0n ? -1n : a > 0n ? 1n : 0n,
  fromNumber: (n) => BigInt(Math.trunc(n)),
  toNumber: (a) => Number(a),
  zero: () => 0n,
  one: () => 1n
};
var integralNumber = {
  div: (a, b) => Math.floor(a / b),
  mod: (a, b) => (a % b + b) % b,
  divMod: (a, b) => {
    const d = Math.floor(a / b);
    return [d, a - d * b];
  },
  quot: (a, b) => Math.trunc(a / b),
  rem: (a, b) => a % b,
  toInteger: (a) => BigInt(Math.trunc(a))
};
var integralBigInt = {
  div: (a, b) => {
    const d = a / b;
    return a < 0n !== b < 0n && a % b !== 0n ? d - 1n : d;
  },
  mod: (a, b) => (a % b + b) % b,
  divMod: (a, b) => {
    const d = integralBigInt.div(a, b);
    return [d, a - d * b];
  },
  quot: (a, b) => a / b,
  rem: (a, b) => a % b,
  toInteger: (a) => a
};
var fractionalNumber = {
  div: (a, b) => a / b,
  recip: (a) => 1 / a,
  fromRational: (num, den) => num / den
};
var floatingNumber = {
  pi: () => Math.PI,
  exp: Math.exp,
  log: Math.log,
  sqrt: Math.sqrt,
  pow: Math.pow,
  sin: Math.sin,
  cos: Math.cos,
  tan: Math.tan,
  asin: Math.asin,
  acos: Math.acos,
  atan: Math.atan,
  atan2: Math.atan2,
  sinh: Math.sinh,
  cosh: Math.cosh,
  tanh: Math.tanh
};
var parseableNumber = {
  parse: (s) => {
    const trimmed = s.trim();
    const n = Number(trimmed);
    if (isNaN(n) && trimmed !== "NaN") {
      return { ok: false, error: `Cannot parse '${trimmed}' as number` };
    }
    return { ok: true, value: n, rest: "" };
  }
};
var parseableBoolean = {
  parse: (s) => {
    const trimmed = s.trim().toLowerCase();
    if (trimmed === "true" || trimmed === "1" || trimmed === "yes") {
      return { ok: true, value: true, rest: "" };
    }
    if (trimmed === "false" || trimmed === "0" || trimmed === "no") {
      return { ok: true, value: false, rest: "" };
    }
    return { ok: false, error: `Cannot parse '${trimmed}' as boolean` };
  }
};
var parseableBigInt = {
  parse: (s) => {
    const trimmed = s.trim();
    try {
      return { ok: true, value: BigInt(trimmed), rest: "" };
    } catch {
      return { ok: false, error: `Cannot parse '${trimmed}' as bigint` };
    }
  }
};
var printableNumber = {
  display: (a) => {
    if (Number.isInteger(a))
      return String(a);
    return a.toLocaleString();
  }
};
var printableString = {
  display: (a) => a
};
var printableBoolean = {
  display: (a) => a ? "true" : "false"
};
var printableDate = {
  display: (a) => a.toISOString()
};
var numberToString = {
  coerce: (a) => String(a)
};
var stringToNumber = {
  coerce: (a) => Number(a)
};
var numberToBigInt = {
  coerce: (a) => BigInt(Math.trunc(a))
};
var bigIntToNumber = {
  coerce: (a) => Number(a)
};
var numberToBoolean = {
  coerce: (a) => a !== 0
};
var booleanToNumber = {
  coerce: (a) => a ? 1 : 0
};
var stringToBoolean = {
  coerce: (a) => a !== "" && a !== "0" && a.toLowerCase() !== "false"
};
var dateToNumber = {
  coerce: (a) => a.getTime()
};
var numberToDate = {
  coerce: (a) => new Date(a)
};
var defaultNumber = {
  defaultValue: () => 0
};
var defaultString = {
  defaultValue: () => ""
};
var defaultBoolean = {
  defaultValue: () => false
};
var defaultBigInt = {
  defaultValue: () => 0n
};
function defaultArray() {
  return { defaultValue: () => [] };
}
function defaultMap() {
  return { defaultValue: () => /* @__PURE__ */ new Map() };
}
function defaultSet() {
  return { defaultValue: () => /* @__PURE__ */ new Set() };
}
var defaultDate = {
  defaultValue: () => /* @__PURE__ */ new Date(0)
};
var copyableNumber = {
  copy: (a) => a
};
var copyableString = {
  copy: (a) => a
};
var copyableBoolean = {
  copy: (a) => a
};
var copyableBigInt = {
  copy: (a) => a
};
var copyableDate = {
  copy: (a) => new Date(a.getTime())
};
function copyableArray(inner) {
  return { copy: (a) => a.map((x) => inner.copy(x)) };
}
function copyableMap(innerK, innerV) {
  return {
    copy: (a) => {
      const m = /* @__PURE__ */ new Map();
      for (const [k, v] of a)
        m.set(innerK.copy(k), innerV.copy(v));
      return m;
    }
  };
}
function copyableSet(inner) {
  return {
    copy: (a) => {
      const s = /* @__PURE__ */ new Set();
      for (const x of a)
        s.add(inner.copy(x));
      return s;
    }
  };
}
var sizedString = {
  size: (a) => a.length,
  isEmpty: (a) => a.length === 0
};
function sizedArray() {
  return {
    size: (a) => a.length,
    isEmpty: (a) => a.length === 0
  };
}
function sizedMap() {
  return {
    size: (a) => a.size,
    isEmpty: (a) => a.size === 0
  };
}
function sizedSet() {
  return {
    size: (a) => a.size,
    isEmpty: (a) => a.size === 0
  };
}
var groupNumber = {
  empty: () => 0,
  combine: (a, b) => a + b,
  invert: (a) => -a
};
var groupBigInt = {
  empty: () => 0n,
  combine: (a, b) => a + b,
  invert: (a) => -a
};

export {
  parCombinePromise,
  parCombineAsyncIterable,
  parCombineArray,
  parCombineIterable,
  getParCombine,
  getParCombineBuilder,
  registerParCombine,
  sum,
  product,
  pow,
  powFrac,
  gcdWith,
  lcmWith,
  clampWith,
  min,
  max,
  minBy,
  maxBy,
  lerpWith,
  inverseLerpWith,
  fromInteger,
  fromInt,
  eqNumber,
  eqBigInt,
  eqString,
  eqBoolean,
  eqDate,
  makeEq,
  eqBy,
  eqStrict,
  eqArray,
  LT,
  EQ_ORD,
  GT,
  ordNumber,
  ordBigInt,
  ordString,
  ordBoolean,
  ordDate,
  makeOrd,
  ordBy,
  reverseOrd,
  ordArray,
  semigroupString,
  semigroupNumber,
  semigroupBigInt,
  semigroupArray,
  monoidString,
  monoidNumber,
  monoidBigInt,
  monoidArray,
  boundedNumber,
  boundedBigInt,
  boundedBoolean,
  boundedString,
  enumNumber,
  enumBoolean,
  enumString,
  numericNumber,
  numericBigInt,
  integralNumber,
  integralBigInt,
  fractionalNumber,
  floatingNumber,
  parseableNumber,
  parseableBoolean,
  parseableBigInt,
  printableNumber,
  printableString,
  printableBoolean,
  printableDate,
  numberToString,
  stringToNumber,
  numberToBigInt,
  bigIntToNumber,
  numberToBoolean,
  booleanToNumber,
  stringToBoolean,
  dateToNumber,
  numberToDate,
  defaultNumber,
  defaultString,
  defaultBoolean,
  defaultBigInt,
  defaultArray,
  defaultMap,
  defaultSet,
  defaultDate,
  copyableNumber,
  copyableString,
  copyableBoolean,
  copyableBigInt,
  copyableDate,
  copyableArray,
  copyableMap,
  copyableSet,
  sizedString,
  sizedArray,
  sizedMap,
  sizedSet,
  groupNumber,
  groupBigInt
};
//# sourceMappingURL=chunk-FCKUZQOW.js.map