import {
  concatAll,
  reverse
} from "./chunk-7KRJXVLP.mjs";
import {
  max,
  min
} from "./chunk-KKQVF4Y5.mjs";
import {
  has
} from "./chunk-WPJQNT3M.mjs";
import {
  getSemigroup,
  identity
} from "./chunk-ZI34HWXZ.mjs";
import {
  __export
} from "./chunk-QK4PKNB3.mjs";

// src/Semigroup.ts
var Semigroup_exports = {};
__export(Semigroup_exports, {
  concatAll: () => concatAll2,
  constant: () => constant,
  first: () => first,
  fold: () => fold,
  getDualSemigroup: () => getDualSemigroup,
  getFirstSemigroup: () => getFirstSemigroup,
  getFunctionSemigroup: () => getFunctionSemigroup,
  getIntercalateSemigroup: () => getIntercalateSemigroup,
  getJoinSemigroup: () => getJoinSemigroup,
  getLastSemigroup: () => getLastSemigroup,
  getMeetSemigroup: () => getMeetSemigroup,
  getObjectSemigroup: () => getObjectSemigroup,
  getStructSemigroup: () => getStructSemigroup,
  getTupleSemigroup: () => getTupleSemigroup,
  intercalate: () => intercalate,
  last: () => last,
  max: () => max2,
  min: () => min2,
  reverse: () => reverse2,
  semigroupAll: () => semigroupAll,
  semigroupAny: () => semigroupAny,
  semigroupProduct: () => semigroupProduct,
  semigroupString: () => semigroupString,
  semigroupSum: () => semigroupSum,
  semigroupVoid: () => semigroupVoid,
  struct: () => struct,
  tuple: () => tuple
});
var min2 = (O) => ({
  concat: min(O)
});
var max2 = (O) => ({
  concat: max(O)
});
var constant = (a) => ({
  concat: () => a
});
var reverse2 = reverse;
var struct = (semigroups) => ({
  concat: (first2, second) => {
    const r = {};
    for (const k in semigroups) {
      if (has.call(semigroups, k)) {
        r[k] = semigroups[k].concat(first2[k], second[k]);
      }
    }
    return r;
  }
});
var tuple = (...semigroups) => ({
  concat: (first2, second) => semigroups.map((s, i) => s.concat(first2[i], second[i]))
});
var intercalate = (middle) => (S) => ({
  concat: (x, y) => S.concat(x, S.concat(middle, y))
});
var first = () => ({ concat: identity });
var last = () => ({ concat: (_, y) => y });
var concatAll2 = concatAll;
var semigroupVoid = constant(void 0);
var getObjectSemigroup = () => ({
  concat: (first2, second) => Object.assign({}, first2, second)
});
var getLastSemigroup = last;
var getFirstSemigroup = first;
var getTupleSemigroup = tuple;
var getStructSemigroup = struct;
var getDualSemigroup = reverse2;
var getJoinSemigroup = max2;
var getMeetSemigroup = min2;
var getIntercalateSemigroup = intercalate;
function fold(S) {
  const concatAllS = concatAll2(S);
  return (startWith, as) => as === void 0 ? concatAllS(startWith) : concatAllS(startWith)(as);
}
var semigroupAll = {
  concat: (x, y) => x && y
};
var semigroupAny = {
  concat: (x, y) => x || y
};
var getFunctionSemigroup = getSemigroup;
var semigroupString = {
  concat: (x, y) => x + y
};
var semigroupSum = {
  concat: (x, y) => x + y
};
var semigroupProduct = {
  concat: (x, y) => x * y
};

export {
  min2 as min,
  max2 as max,
  constant,
  reverse2 as reverse,
  struct,
  tuple,
  intercalate,
  first,
  last,
  concatAll2 as concatAll,
  semigroupVoid,
  getObjectSemigroup,
  getLastSemigroup,
  getFirstSemigroup,
  getTupleSemigroup,
  getStructSemigroup,
  getDualSemigroup,
  getJoinSemigroup,
  getMeetSemigroup,
  getIntercalateSemigroup,
  fold,
  semigroupAll,
  semigroupAny,
  getFunctionSemigroup,
  semigroupString,
  semigroupSum,
  semigroupProduct,
  Semigroup_exports
};
