import * as tsplus_module_1 from "@tsplus/stdlib/collections/Chunk/empty";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/succeedNow";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/append";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/zipWith";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/suspendSucceed";
import { concreteChunkId } from "@tsplus/stdlib/collections/Chunk/definition";
/**
 * Filters this chunk by the specified effectful predicate, retaining all
 * elements for which the predicate evaluates to true.
 *
 * @tsplus fluent Chunk filterEffect
 */

export function filterEffect_(self, f, __tsplusTrace) {
  return tsplus_module_5.suspendSucceed(() => {
    const iterator = self._arrayLikeIterator();

    let next;
    let dest = tsplus_module_2.succeedNow(tsplus_module_1.empty(), __tsplusTrace);

    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 = tsplus_module_4.zipWith_(dest, () => f(a), (d, b) => b ? tsplus_module_3.append_(d, a) : d, __tsplusTrace);
        i++;
      }
    }

    return dest;
  }, __tsplusTrace);
}
/**
 * Filters this chunk by the specified effectful predicate, retaining all elements for
 * which the predicate evaluates to true.
 *
 * @tsplus static Chunk/Aspects filterEffect
 */

export const filterEffect = (f, __tsplusTrace) => self => filterEffect_(self, f, __tsplusTrace);
//# sourceMappingURL=filterEffect.mjs.map