"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.filterNotParN =
  exports.filterNotParN_ =
  exports.filterNotPar =
  exports.filterNotPar_ =
  exports.filterNot_ =
  exports.filterNot =
  exports.filterParN =
  exports.filterParN_ =
  exports.filterPar =
  exports.filterPar_ =
  exports.filter_ =
  exports.filter =
    void 0
// tracing: off
const Chunk = __importStar(require("../Collections/Immutable/Chunk"))
const Function_1 = require("../Function")
const I = __importStar(require("../Iterable"))
const O = __importStar(require("../Option"))
const core = __importStar(require("./core"))
const forEach = __importStar(require("./excl-forEach"))
const map = __importStar(require("./map"))
const zipWith = __importStar(require("./zipWith"))
/**
 * Filters the collection using the specified effectual predicate.
 *
 * @dataFirst filter_
 */
function filter(f, __trace) {
  return (as) => filter_(as, f, __trace)
}
exports.filter = filter
/**
 * Filters the collection using the specified effectual predicate.
 */
function filter_(as, f, __trace) {
  return core.suspend(
    () =>
      I.reduce_(
        as,
        core.succeedWith(() => []),
        (io, a) =>
          zipWith.zipWith_(
            io,
            core.suspend(() => f(a)),
            (as_, p) => {
              if (p) {
                as_.push(a)
              }
              return as_
            }
          )
      ),
    __trace
  )
}
exports.filter_ = filter_
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filter` for a sequential version of it.
 */
function filterPar_(as, f, __trace) {
  return map.map_(
    forEach.forEachPar_(
      as,
      (a) => map.map_(f(a), (b) => (b ? O.some(a) : O.none)),
      __trace
    ),
    Chunk.compact
  )
}
exports.filterPar_ = filterPar_
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filter` for a sequential version of it.
 *
 * @dataFirst filterPar_
 */
function filterPar(f, __trace) {
  return (as) => filterPar_(as, f, __trace)
}
exports.filterPar = filterPar
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filter` for a sequential version of it.
 *
 * This method will use up to `n` fibers.
 */
function filterParN_(as, n, f, __trace) {
  return map.map_(
    forEach.forEachParN_(
      as,
      n,
      (a) => map.map_(f(a), (b) => (b ? O.some(a) : O.none)),
      __trace
    ),
    Chunk.compact
  )
}
exports.filterParN_ = filterParN_
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filter` for a sequential version of it.
 *
 * This method will use up to `n` fibers.
 *
 * @dataFirst filterParN_
 */
function filterParN(n, f, __trace) {
  return (as) => filterParN_(as, n, f, __trace)
}
exports.filterParN = filterParN
/**
 * Filters the collection using the specified effectual predicate, removing
 * all elements that satisfy the predicate.
 *
 * @dataFirst filterNot_
 */
function filterNot(f, __trace) {
  return (as) => filterNot_(as, f, __trace)
}
exports.filterNot = filterNot
/**
 * Filters the collection using the specified effectual predicate, removing
 * all elements that satisfy the predicate.
 */
function filterNot_(as, f, __trace) {
  return filter_(as, (x) => map.map_(f(x), (b) => !b), __trace)
}
exports.filterNot_ = filterNot_
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filterNot` for a sequential version of it.
 */
function filterNotPar_(as, f, __trace) {
  return filterPar_(as, (x) => map.map_(f(x), (b) => !b), __trace)
}
exports.filterNotPar_ = filterNotPar_
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filterNot` for a sequential version of it.
 *
 * @dataFirst filterNotPar_
 */
function filterNotPar(f, __trace) {
  return (as) => filterNotPar_(as, f, __trace)
}
exports.filterNotPar = filterNotPar
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filterNot` for a sequential version of it.
 */
function filterNotParN_(as, n, f, __trace) {
  return filterParN_(as, n, (x) => map.map_(f(x), (b) => !b), __trace)
}
exports.filterNotParN_ = filterNotParN_
/**
 * Filters the collection in parallel using the specified effectual predicate.
 * See `filterNot` for a sequential version of it.
 *
 * @dataFirst filterNotParN_
 */
function filterNotParN(n, f, __trace) {
  return (as) => filterNotParN_(as, n, f, __trace)
}
exports.filterNotParN = filterNotParN
//# sourceMappingURL=filter.js.map
