import * as tracing_1 from "../../../../Tracing";
const fileName_1 = "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/filterM.ts";
import * as core from "../../../../Effect/core";
import * as coreZip from "../../../../Effect/zipWith";
import * as Chunk from "../core";
import { concreteId } from "../definition";
/**
 * Filters this chunk by the specified effectful predicate, retaining all elements for
 * which the predicate evaluates to true.
 */

export function filterM_(self, f) {
  return core.suspend(() => {
    const iterator = self.arrayLikeIterator();
    let next;
    let dest = core.succeed(Chunk.empty(), fileName_1 + ":18:58");

    while ((next = iterator.next()) && !next.done) {
      const array = next.value;
      const len = array.length;
      let i = 0;

      while (i < len) {
        const a = array[i];
        dest = coreZip.zipWith_(dest, f(a), (d, b) => b ? Chunk.append_(d, a) : d, fileName_1 + ":26:32");
        i++;
      }
    }

    return dest;
  }, fileName_1 + ":15:22");
}
/**
 * Filters this chunk by the specified effectful predicate, retaining all elements for
 * which the predicate evaluates to true.
 *
 * @ets_data_first filterM_
 */

export function filterM(f) {
  return self => filterM_(self, f);
}
//# sourceMappingURL=filterM.js.map