"use strict"
var __createBinding =
  (this && this.__createBinding) ||
  (Object.create
    ? function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        Object.defineProperty(o, k2, {
          enumerable: true,
          get: function () {
            return m[k]
          }
        })
      }
    : function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        o[k2] = m[k]
      })
var __setModuleDefault =
  (this && this.__setModuleDefault) ||
  (Object.create
    ? function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v })
      }
    : function (o, v) {
        o["default"] = v
      })
var __importStar =
  (this && this.__importStar) ||
  function (mod) {
    if (mod && mod.__esModule) return mod
    var result = {}
    if (mod != null)
      for (var k in mod)
        if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
          __createBinding(result, mod, k)
    __setModuleDefault(result, mod)
    return result
  }
Object.defineProperty(exports, "__esModule", { value: true })
exports.collectParN =
  exports.collectParN_ =
  exports.collectPar_ =
  exports.collectPar =
  exports.collect_ =
  exports.collect =
    void 0
// tracing: off
const Chunk = __importStar(require("../Collections/Immutable/Chunk"))
const excl_forEach_1 = require("./excl-forEach")
const map_1 = require("./map")
const optional_1 = require("./optional")
/**
 * Evaluate each effect in the structure from left to right, collecting the
 * the successful values and discarding the empty cases. For a parallel version, see `collectPar`.
 *
 * @dataFirst collect_
 */
function collect(f, __trace) {
  return (self) => collect_(self, f, __trace)
}
exports.collect = collect
/**
 * Evaluate each effect in the structure from left to right, collecting the
 * the successful values and discarding the empty cases. For a parallel version, see `collectPar`.
 */
function collect_(self, f, __trace) {
  return (0, map_1.map_)(
    (0, excl_forEach_1.forEach_)(self, (a) => (0, optional_1.optional)(f(a)), __trace),
    Chunk.compact
  )
}
exports.collect_ = collect_
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 *
 * @dataFirst collectPar_
 */
function collectPar(f, __trace) {
  return (self) => collectPar_(self, f, __trace)
}
exports.collectPar = collectPar
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 */
function collectPar_(self, f, __trace) {
  return (0, map_1.map_)(
    (0, excl_forEach_1.forEachPar_)(
      self,
      (a) => (0, optional_1.optional)(f(a)),
      __trace
    ),
    Chunk.compact
  )
}
exports.collectPar_ = collectPar_
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 *
 * Unlike `collectPar`, this method will use at most up to `n` fibers.
 */
function collectParN_(self, n, f, __trace) {
  return (0, map_1.map_)(
    (0, excl_forEach_1.forEachParN_)(
      self,
      n,
      (a) => (0, optional_1.optional)(f(a)),
      __trace
    ),
    Chunk.compact
  )
}
exports.collectParN_ = collectParN_
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 *
 * Unlike `collectPar`, this method will use at most up to `n` fibers.
 *
 * @dataFirst collectParN_
 */
function collectParN(n, f, __trace) {
  return (self) => collectParN_(self, n, f, __trace)
}
exports.collectParN = collectParN
//# sourceMappingURL=collect.js.map
