import * as tsplus_module_1 from "@tsplus/stdlib/collections/List/reverse";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/definition";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/List/empty";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/List/prepend";
import * as tsplus_module_6 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_7 from "@effect/core/stream/Sink/operations/foldEffect";
import * as tsplus_module_8 from "@effect/core/stream/Sink/operations/map";
/**
 * Accumulates incoming elements into a chunk as long as they verify effectful
 * predicate `p`.
 *
 * @tsplus static ets/Sink/Ops collectAllWhileEffect
 */

export function collectAllWhileEffect(p, __tsplusTrace) {
  return tsplus_module_8.map_(tsplus_module_7.foldEffect(() => tsplus_module_4.make(tsplus_module_3.empty(), true), tuple => tuple.get(1), ({
    tuple: [as, _]
  }, a) => tsplus_module_6.map_(p(a), b => b ? tsplus_module_4.make(tsplus_module_5.prepend_(as, a), true) : tsplus_module_4.make(as, false), __tsplusTrace), __tsplusTrace), ({
    tuple: [inputs, _]
  }) => tsplus_module_2.from(tsplus_module_1.reverse(inputs)), __tsplusTrace);
}
//# sourceMappingURL=collectAllWhileEffect.mjs.map