import * as tsplus_module_1 from "@effect/core/stream/Channel/operations/unit";
import * as tsplus_module_2 from "@effect/core/io/Exit/operations/succeed";
import * as tsplus_module_3 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/zipRight";
import * as tsplus_module_5 from "@tsplus/stdlib/collections/Chunk/reduce";
import * as tsplus_module_6 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_7 from "@effect/core/io/Exit/operations/fail";
import * as tsplus_module_8 from "@effect/core/stream/Channel/operations/readWith";
import * as tsplus_module_9 from "@effect/core/stream/Channel/operations/pipeTo";
import * as tsplus_module_10 from "@effect/core/stream/Channel/operations/mapOutEffect";
import * as tsplus_module_11 from "@effect/core/stream/Channel/operations/drain";
import * as tsplus_module_12 from "@effect/core/stream/Channel/operations/runScoped";
import * as tsplus_module_13 from "@effect/core/io/Effect/operations/unit";
import { concreteStream } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
/**
 * Like `Stream.runIntoQueue`, but provides the result as a scoped effect to
 * allow for scope composition.
 *
 * @tsplus fluent ets/Stream runIntoQueueElementsScoped
 */

export function runIntoQueueElementsScoped_(self, queue, __tsplusTrace) {
  const writer = tsplus_module_8.readWith(input => tsplus_module_4.zipRight_(tsplus_module_5.reduce_(input, tsplus_module_1.unit, (channel, a) => tsplus_module_4.zipRight_(channel, () => tsplus_module_3.write(() => tsplus_module_2.succeed(a)))), () => writer), err => tsplus_module_3.write(() => tsplus_module_7.fail(tsplus_module_6.some(err))), () => tsplus_module_3.write(() => tsplus_module_7.fail(tsplus_module_6.none)));
  void 0;
  return tsplus_module_13.unit_(tsplus_module_12.runScoped(tsplus_module_11.drain(tsplus_module_10.mapOutEffect_(tsplus_module_9.pipeTo_(self.channel, () => writer), take => queue().offer(take, __tsplusTrace)))), __tsplusTrace);
}
/**
 * Like `Stream.runIntoQueue`, but provides the result as a scoped effect to
 * allow for scope composition.
 *
 * @tsplus static ets/Stream/Aspects runIntoQueueElementsScoped
 */

export const runIntoQueueElementsScoped = (queue, __tsplusTrace) => self => runIntoQueueElementsScoped_(self, queue, __tsplusTrace);
//# sourceMappingURL=runIntoQueueElementsScoped.mjs.map