"use strict";Object.defineProperty(exports, "__esModule", {value: true});














var _chunk67GC34HGjs = require('./chunk-67GC34HG.js');




var _chunk7K74W2G3js = require('./chunk-7K74W2G3.js');


var _chunkQC33EBBCjs = require('./chunk-QC33EBBC.js');




var _chunkQ2LZCTWPjs = require('./chunk-Q2LZCTWP.js');



var _chunkEBISTSVAjs = require('./chunk-EBISTSVA.js');






var _chunkOTKMOSH2js = require('./chunk-OTKMOSH2.js');




var _chunkSQA7G4TEjs = require('./chunk-SQA7G4TE.js');


var _chunk6C3VEZWHjs = require('./chunk-6C3VEZWH.js');

// src/NonEmptyArray.ts
var NonEmptyArray_exports = {};
_chunk6C3VEZWHjs.__export.call(void 0, NonEmptyArray_exports, {
  Alt: () => Alt,
  Applicative: () => Applicative,
  Apply: () => Apply,
  Chain: () => Chain,
  Comonad: () => Comonad,
  Do: () => Do,
  Foldable: () => Foldable,
  FoldableWithIndex: () => FoldableWithIndex,
  Functor: () => Functor,
  FunctorWithIndex: () => FunctorWithIndex,
  Monad: () => Monad,
  Pointed: () => Pointed,
  Traversable: () => Traversable,
  TraversableWithIndex: () => TraversableWithIndex,
  URI: () => URI,
  alt: () => alt,
  altW: () => altW,
  ap: () => ap,
  apFirst: () => apFirst2,
  apS: () => apS2,
  apSecond: () => apSecond2,
  append: () => append,
  appendW: () => appendW,
  bind: () => bind2,
  bindTo: () => bindTo2,
  chain: () => chain,
  chainFirst: () => chainFirst2,
  chainWithIndex: () => chainWithIndex,
  chop: () => chop,
  chunksOf: () => chunksOf,
  concat: () => concat,
  concatAll: () => concatAll2,
  concatW: () => concatW,
  cons: () => cons,
  copy: () => copy,
  duplicate: () => duplicate,
  extend: () => extend,
  extract: () => extract,
  filter: () => filter,
  filterWithIndex: () => filterWithIndex,
  flap: () => flap2,
  flatMap: () => flatMap,
  flatten: () => flatten,
  fold: () => fold,
  foldMap: () => foldMap2,
  foldMapWithIndex: () => foldMapWithIndex2,
  fromArray: () => fromArray,
  fromReadonlyNonEmptyArray: () => fromReadonlyNonEmptyArray2,
  getEq: () => getEq2,
  getSemigroup: () => getSemigroup,
  getShow: () => getShow2,
  getUnionSemigroup: () => getUnionSemigroup,
  group: () => group,
  groupBy: () => groupBy,
  groupSort: () => groupSort,
  head: () => head2,
  init: () => init,
  insertAt: () => insertAt,
  intercalate: () => intercalate2,
  intersperse: () => intersperse,
  isNonEmpty: () => isNonEmpty,
  isOutOfBound: () => isOutOfBound,
  last: () => last2,
  let: () => let_2,
  makeBy: () => makeBy,
  map: () => map,
  mapWithIndex: () => mapWithIndex,
  matchLeft: () => matchLeft,
  matchRight: () => matchRight,
  max: () => max2,
  min: () => min2,
  modifyAt: () => modifyAt,
  modifyHead: () => modifyHead,
  modifyLast: () => modifyLast,
  nonEmptyArray: () => nonEmptyArray,
  of: () => of,
  prepend: () => prepend,
  prependAll: () => prependAll,
  prependToAll: () => prependToAll,
  prependW: () => prependW,
  range: () => range,
  reduce: () => reduce2,
  reduceRight: () => reduceRight2,
  reduceRightWithIndex: () => reduceRightWithIndex2,
  reduceWithIndex: () => reduceWithIndex2,
  replicate: () => replicate,
  reverse: () => reverse,
  rotate: () => rotate,
  sequence: () => sequence,
  snoc: () => snoc,
  sort: () => sort,
  sortBy: () => sortBy,
  splitAt: () => splitAt,
  tail: () => tail,
  traverse: () => traverse,
  traverseWithIndex: () => traverseWithIndex,
  unappend: () => unappend,
  uncons: () => uncons,
  union: () => union,
  uniq: () => uniq,
  unprepend: () => unprepend,
  unsafeInsertAt: () => unsafeInsertAt,
  unsafeUpdateAt: () => unsafeUpdateAt,
  unsnoc: () => unsnoc,
  unzip: () => unzip,
  updateAt: () => updateAt,
  updateHead: () => updateHead,
  updateLast: () => updateLast,
  zip: () => zip,
  zipWith: () => zipWith
});
var isNonEmpty = (as) => as.length > 0;
var isOutOfBound = (i, as) => i < 0 || i >= as.length;
var prependW = (head3) => (tail2) => [head3, ...tail2];
var prepend = prependW;
var appendW = (end) => (init2) => [...init2, end];
var append = appendW;
var unsafeInsertAt = (i, a, as) => {
  if (isNonEmpty(as)) {
    const xs = fromReadonlyNonEmptyArray2(as);
    xs.splice(i, 0, a);
    return xs;
  }
  return [a];
};
var unsafeUpdateAt = (i, a, as) => {
  const xs = fromReadonlyNonEmptyArray2(as);
  xs[i] = a;
  return xs;
};
var uniq = (E) => (as) => {
  if (as.length === 1) {
    return copy(as);
  }
  const out = [head2(as)];
  const rest = tail(as);
  for (const a of rest) {
    if (out.every((o) => !E.equals(o, a))) {
      out.push(a);
    }
  }
  return out;
};
var sortBy = (ords) => {
  if (isNonEmpty(ords)) {
    const M = _chunkQC33EBBCjs.getMonoid.call(void 0, );
    return sort(ords.reduce(M.concat, M.empty));
  }
  return copy;
};
var union = (E) => {
  const uniqE = uniq(E);
  return (second) => (first) => uniqE(_chunkSQA7G4TEjs.pipe.call(void 0, first, concat(second)));
};
var rotate = (n) => (as) => {
  const len = as.length;
  const m = Math.round(n) % len;
  if (isOutOfBound(Math.abs(m), as) || m === 0) {
    return copy(as);
  }
  if (m < 0) {
    const [f, s] = splitAt(-m)(as);
    return _chunkSQA7G4TEjs.pipe.call(void 0, s, concat(f));
  } else {
    return rotate(m - len)(as);
  }
};
var fromReadonlyNonEmptyArray2 = _chunkOTKMOSH2js.fromReadonlyNonEmptyArray;
var fromArray = (as) => isNonEmpty(as) ? _chunkOTKMOSH2js.some.call(void 0, as) : _chunkOTKMOSH2js.none;
var makeBy = (f) => (n) => {
  const j = Math.max(0, Math.floor(n));
  const out = [f(0)];
  for (let i = 1; i < j; i++) {
    out.push(f(i));
  }
  return out;
};
var replicate = (a) => makeBy(() => a);
var range = (start, end) => start <= end ? makeBy((i) => start + i)(end - start + 1) : [start];
var unprepend = (as) => [head2(as), tail(as)];
var unappend = (as) => [init(as), last2(as)];
function concatW(second) {
  return (first) => first.concat(second);
}
function concat(x, y) {
  return y ? x.concat(y) : (y2) => y2.concat(x);
}
var reverse = (as) => [last2(as), ...as.slice(0, -1).reverse()];
function group(E) {
  return (as) => {
    const len = as.length;
    if (len === 0) {
      return [];
    }
    const out = [];
    let head3 = as[0];
    let nea = [head3];
    for (let i = 1; i < len; i++) {
      const a = as[i];
      if (E.equals(a, head3)) {
        nea.push(a);
      } else {
        out.push(nea);
        head3 = a;
        nea = [head3];
      }
    }
    out.push(nea);
    return out;
  };
}
var groupBy = (f) => (as) => {
  const out = {};
  for (const a of as) {
    const k = f(a);
    if (_chunkOTKMOSH2js.has.call(out, k)) {
      out[k].push(a);
    } else {
      out[k] = [a];
    }
  }
  return out;
};
var sort = (O) => (as) => as.slice().sort(O.compare);
var insertAt = (i, a) => (as) => i < 0 || i > as.length ? _chunkOTKMOSH2js.none : _chunkOTKMOSH2js.some.call(void 0, unsafeInsertAt(i, a, as));
var updateAt = (i, a) => modifyAt(i, () => a);
var modifyAt = (i, f) => (as) => isOutOfBound(i, as) ? _chunkOTKMOSH2js.none : _chunkOTKMOSH2js.some.call(void 0, unsafeUpdateAt(i, f(as[i]), as));
var copy = fromReadonlyNonEmptyArray2;
var of = (a) => [a];
var zipWith = (as, bs, f) => {
  const cs = [f(as[0], bs[0])];
  const len = Math.min(as.length, bs.length);
  for (let i = 1; i < len; i++) {
    cs[i] = f(as[i], bs[i]);
  }
  return cs;
};
function zip(as, bs) {
  if (bs === void 0) {
    return (bs2) => zip(bs2, as);
  }
  return zipWith(as, bs, (a, b) => [a, b]);
}
var unzip = (abs) => {
  const fa = [abs[0][0]];
  const fb = [abs[0][1]];
  for (let i = 1; i < abs.length; i++) {
    fa[i] = abs[i][0];
    fb[i] = abs[i][1];
  }
  return [fa, fb];
};
var prependAll = (middle) => (as) => {
  const out = [middle, as[0]];
  for (let i = 1; i < as.length; i++) {
    out.push(middle, as[i]);
  }
  return out;
};
var intersperse = (middle) => (as) => {
  const rest = tail(as);
  return isNonEmpty(rest) ? _chunkSQA7G4TEjs.pipe.call(void 0, rest, prependAll(middle), prepend(head2(as))) : copy(as);
};
var foldMapWithIndex2 = _chunk67GC34HGjs.foldMapWithIndex;
var foldMap2 = _chunk67GC34HGjs.foldMap;
var chainWithIndex = (f) => (as) => {
  const out = fromReadonlyNonEmptyArray2(f(0, head2(as)));
  for (let i = 1; i < as.length; i++) {
    out.push(...f(i, as[i]));
  }
  return out;
};
var chop = (f) => (as) => {
  const [b, rest] = f(as);
  const out = [b];
  let next = rest;
  while (isNonEmpty(next)) {
    const [b2, rest2] = f(next);
    out.push(b2);
    next = rest2;
  }
  return out;
};
var splitAt = (n) => (as) => {
  const m = Math.max(1, n);
  return m >= as.length ? [copy(as), []] : [_chunkSQA7G4TEjs.pipe.call(void 0, as.slice(1, m), prepend(head2(as))), as.slice(m)];
};
var chunksOf = (n) => chop(splitAt(n));
var _map = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, map(f));
var _mapWithIndex = (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, mapWithIndex(f));
var _ap = (fab, fa) => _chunkSQA7G4TEjs.pipe.call(void 0, fab, ap(fa));
var _extend = (wa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, wa, extend(f));
var _reduce = (fa, b, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, reduce2(b, f));
var _foldMap = (M) => {
  const foldMapM = foldMap2(M);
  return (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, foldMapM(f));
};
var _reduceRight = (fa, b, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, reduceRight2(b, f));
var _traverse = (F) => {
  const traverseF = traverse(F);
  return (ta, f) => _chunkSQA7G4TEjs.pipe.call(void 0, ta, traverseF(f));
};
var _alt = (fa, that) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, alt(that));
var _reduceWithIndex = (fa, b, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, reduceWithIndex2(b, f));
var _foldMapWithIndex = (M) => {
  const foldMapWithIndexM = foldMapWithIndex2(M);
  return (fa, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, foldMapWithIndexM(f));
};
var _reduceRightWithIndex = (fa, b, f) => _chunkSQA7G4TEjs.pipe.call(void 0, fa, reduceRightWithIndex2(b, f));
var _traverseWithIndex = (F) => {
  const traverseWithIndexF = traverseWithIndex(F);
  return (ta, f) => _chunkSQA7G4TEjs.pipe.call(void 0, ta, traverseWithIndexF(f));
};
var altW = (that) => (as) => _chunkSQA7G4TEjs.pipe.call(void 0, as, concatW(that()));
var alt = altW;
var ap = (as) => flatMap((f) => _chunkSQA7G4TEjs.pipe.call(void 0, as, map(f)));
var flatMap = /* @__PURE__ */ _chunkSQA7G4TEjs.dual.call(void 0, 
  2,
  (ma, f) => _chunkSQA7G4TEjs.pipe.call(void 0, 
    ma,
    chainWithIndex((i, a) => f(a, i))
  )
);
var extend = (f) => (as) => {
  let next = tail(as);
  const out = [f(as)];
  while (isNonEmpty(next)) {
    out.push(f(next));
    next = tail(next);
  }
  return out;
};
var duplicate = /* @__PURE__ */ extend(_chunkSQA7G4TEjs.identity);
var flatten = /* @__PURE__ */ flatMap(_chunkSQA7G4TEjs.identity);
var map = (f) => mapWithIndex((_, a) => f(a));
var mapWithIndex = (f) => (as) => {
  const out = [f(0, head2(as))];
  for (let i = 1; i < as.length; i++) {
    out.push(f(i, as[i]));
  }
  return out;
};
var reduce2 = _chunk67GC34HGjs.reduce;
var reduceWithIndex2 = _chunk67GC34HGjs.reduceWithIndex;
var reduceRight2 = _chunk67GC34HGjs.reduceRight;
var reduceRightWithIndex2 = _chunk67GC34HGjs.reduceRightWithIndex;
var traverse = (F) => {
  const traverseWithIndexF = traverseWithIndex(F);
  return (f) => traverseWithIndexF((_, a) => f(a));
};
var sequence = (F) => traverseWithIndex(F)((_, a) => a);
var traverseWithIndex = (F) => (f) => (as) => {
  let out = F.map(f(0, head2(as)), of);
  for (let i = 1; i < as.length; i++) {
    out = F.ap(
      F.map(out, (bs) => (b) => _chunkSQA7G4TEjs.pipe.call(void 0, bs, append(b))),
      f(i, as[i])
    );
  }
  return out;
};
var extract = _chunk67GC34HGjs.head;
var URI = "NonEmptyArray";
var getShow2 = _chunk67GC34HGjs.getShow;
var getSemigroup = () => ({
  concat
});
var getEq2 = _chunk67GC34HGjs.getEq;
var getUnionSemigroup = (E) => {
  const unionE = union(E);
  return {
    concat: (first, second) => unionE(second)(first)
  };
};
var Functor = {
  URI,
  map: _map
};
var flap2 = /* @__PURE__ */ _chunk7K74W2G3js.flap.call(void 0, Functor);
var Pointed = {
  URI,
  of
};
var FunctorWithIndex = {
  URI,
  map: _map,
  mapWithIndex: _mapWithIndex
};
var Apply = {
  URI,
  map: _map,
  ap: _ap
};
var apFirst2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apFirst.call(void 0, Apply);
var apSecond2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apSecond.call(void 0, Apply);
var Applicative = {
  URI,
  map: _map,
  ap: _ap,
  of
};
var Chain = {
  URI,
  map: _map,
  ap: _ap,
  chain: flatMap
};
var chainFirst2 = /* @__PURE__ */ _chunkEBISTSVAjs.chainFirst.call(void 0, Chain);
var Monad = {
  URI,
  map: _map,
  ap: _ap,
  of,
  chain: flatMap
};
var Foldable = {
  URI,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight
};
var FoldableWithIndex = {
  URI,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  reduceWithIndex: _reduceWithIndex,
  foldMapWithIndex: _foldMapWithIndex,
  reduceRightWithIndex: _reduceRightWithIndex
};
var Traversable = {
  URI,
  map: _map,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  traverse: _traverse,
  sequence
};
var TraversableWithIndex = {
  URI,
  map: _map,
  mapWithIndex: _mapWithIndex,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  traverse: _traverse,
  sequence,
  reduceWithIndex: _reduceWithIndex,
  foldMapWithIndex: _foldMapWithIndex,
  reduceRightWithIndex: _reduceRightWithIndex,
  traverseWithIndex: _traverseWithIndex
};
var Alt = {
  URI,
  map: _map,
  alt: _alt
};
var Comonad = {
  URI,
  map: _map,
  extend: _extend,
  extract
};
var Do = /* @__PURE__ */ of(_chunkOTKMOSH2js.emptyRecord);
var bindTo2 = /* @__PURE__ */ _chunk7K74W2G3js.bindTo.call(void 0, Functor);
var let_2 = /* @__PURE__ */ _chunk7K74W2G3js.let_.call(void 0, Functor);
var bind2 = /* @__PURE__ */ _chunkEBISTSVAjs.bind.call(void 0, Chain);
var apS2 = /* @__PURE__ */ _chunkQ2LZCTWPjs.apS.call(void 0, Apply);
var head2 = _chunk67GC34HGjs.head;
var tail = (as) => as.slice(1);
var last2 = _chunk67GC34HGjs.last;
var init = (as) => as.slice(0, -1);
var min2 = _chunk67GC34HGjs.min;
var max2 = _chunk67GC34HGjs.max;
var concatAll2 = (S) => (as) => as.reduce(S.concat);
var matchLeft = (f) => (as) => f(head2(as), tail(as));
var matchRight = (f) => (as) => f(init(as), last2(as));
var modifyHead = (f) => (as) => [f(head2(as)), ...tail(as)];
var updateHead = (a) => modifyHead(() => a);
var modifyLast = (f) => (as) => _chunkSQA7G4TEjs.pipe.call(void 0, init(as), append(f(last2(as))));
var updateLast = (a) => modifyLast(() => a);
var intercalate2 = _chunk67GC34HGjs.intercalate;
var chain = flatMap;
function groupSort(O) {
  const sortO = sort(O);
  const groupO = group(O);
  return (as) => isNonEmpty(as) ? groupO(sortO(as)) : [];
}
function filter(predicate) {
  return filterWithIndex((_, a) => predicate(a));
}
var filterWithIndex = (predicate) => (as) => fromArray(as.filter((a, i) => predicate(i, a)));
var uncons = unprepend;
var unsnoc = unappend;
function cons(head3, tail2) {
  return tail2 === void 0 ? prepend(head3) : _chunkSQA7G4TEjs.pipe.call(void 0, tail2, prepend(head3));
}
var snoc = (init2, end) => _chunkSQA7G4TEjs.pipe.call(void 0, init2, append(end));
var prependToAll = prependAll;
var fold = _chunk67GC34HGjs.concatAll;
var nonEmptyArray = {
  URI,
  of,
  map: _map,
  mapWithIndex: _mapWithIndex,
  ap: _ap,
  chain: flatMap,
  extend: _extend,
  extract,
  reduce: _reduce,
  foldMap: _foldMap,
  reduceRight: _reduceRight,
  traverse: _traverse,
  sequence,
  reduceWithIndex: _reduceWithIndex,
  foldMapWithIndex: _foldMapWithIndex,
  reduceRightWithIndex: _reduceRightWithIndex,
  traverseWithIndex: _traverseWithIndex,
  alt: _alt
};

















































































































exports.isNonEmpty = isNonEmpty; exports.isOutOfBound = isOutOfBound; exports.prependW = prependW; exports.prepend = prepend; exports.appendW = appendW; exports.append = append; exports.unsafeInsertAt = unsafeInsertAt; exports.unsafeUpdateAt = unsafeUpdateAt; exports.uniq = uniq; exports.sortBy = sortBy; exports.union = union; exports.rotate = rotate; exports.fromReadonlyNonEmptyArray = fromReadonlyNonEmptyArray2; exports.fromArray = fromArray; exports.makeBy = makeBy; exports.replicate = replicate; exports.range = range; exports.unprepend = unprepend; exports.unappend = unappend; exports.concatW = concatW; exports.concat = concat; exports.reverse = reverse; exports.group = group; exports.groupBy = groupBy; exports.sort = sort; exports.insertAt = insertAt; exports.updateAt = updateAt; exports.modifyAt = modifyAt; exports.copy = copy; exports.of = of; exports.zipWith = zipWith; exports.zip = zip; exports.unzip = unzip; exports.prependAll = prependAll; exports.intersperse = intersperse; exports.foldMapWithIndex = foldMapWithIndex2; exports.foldMap = foldMap2; exports.chainWithIndex = chainWithIndex; exports.chop = chop; exports.splitAt = splitAt; exports.chunksOf = chunksOf; exports.altW = altW; exports.alt = alt; exports.ap = ap; exports.flatMap = flatMap; exports.extend = extend; exports.duplicate = duplicate; exports.flatten = flatten; exports.map = map; exports.mapWithIndex = mapWithIndex; exports.reduce = reduce2; exports.reduceWithIndex = reduceWithIndex2; exports.reduceRight = reduceRight2; exports.reduceRightWithIndex = reduceRightWithIndex2; exports.traverse = traverse; exports.sequence = sequence; exports.traverseWithIndex = traverseWithIndex; exports.extract = extract; exports.URI = URI; exports.getShow = getShow2; exports.getSemigroup = getSemigroup; exports.getEq = getEq2; exports.getUnionSemigroup = getUnionSemigroup; exports.Functor = Functor; exports.flap = flap2; exports.Pointed = Pointed; exports.FunctorWithIndex = FunctorWithIndex; exports.Apply = Apply; exports.apFirst = apFirst2; exports.apSecond = apSecond2; exports.Applicative = Applicative; exports.Chain = Chain; exports.chainFirst = chainFirst2; exports.Monad = Monad; exports.Foldable = Foldable; exports.FoldableWithIndex = FoldableWithIndex; exports.Traversable = Traversable; exports.TraversableWithIndex = TraversableWithIndex; exports.Alt = Alt; exports.Comonad = Comonad; exports.Do = Do; exports.bindTo = bindTo2; exports.let_ = let_2; exports.bind = bind2; exports.apS = apS2; exports.head = head2; exports.tail = tail; exports.last = last2; exports.init = init; exports.min = min2; exports.max = max2; exports.concatAll = concatAll2; exports.matchLeft = matchLeft; exports.matchRight = matchRight; exports.modifyHead = modifyHead; exports.updateHead = updateHead; exports.modifyLast = modifyLast; exports.updateLast = updateLast; exports.intercalate = intercalate2; exports.chain = chain; exports.groupSort = groupSort; exports.filter = filter; exports.filterWithIndex = filterWithIndex; exports.uncons = uncons; exports.unsnoc = unsnoc; exports.cons = cons; exports.snoc = snoc; exports.prependToAll = prependToAll; exports.fold = fold; exports.nonEmptyArray = nonEmptyArray; exports.NonEmptyArray_exports = NonEmptyArray_exports;
