import * as tsplus_module_1 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/unwrapScoped";
import * as tsplus_module_3 from "@effect/core/stream/Channel/operations/pipeTo";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_5 from "@tsplus/stdlib/data/Maybe/definition";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/fromEffect";
import * as tsplus_module_7 from "@effect/core/stream/Channel/operations/flatMap";
import * as tsplus_module_8 from "@effect/core/stream/Channel/operations/zipRight";
import * as tsplus_module_9 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_10 from "@effect/core/stream/Channel/operations/readWith";
import { concreteStream, StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
/**
 * Transduce a stream using a chunk processing function.
 *
 * @tsplus static ets/Stream/Ops transducePush
 */

export function transducePush(push, __tsplusTrace) {
  return stream => {
    const channel = tsplus_module_2.unwrapScoped(tsplus_module_1.map_(push(), push => pull(push, __tsplusTrace), __tsplusTrace));
    void 0;
    return new StreamInternal(tsplus_module_3.pipeTo_(stream.channel, () => channel));
  };
}

function pull(push, __tsplusTrace) {
  return tsplus_module_10.readWith(input => tsplus_module_8.zipRight_(tsplus_module_7.flatMap_(tsplus_module_6.fromEffect(() => push(tsplus_module_5.some(input))), out => tsplus_module_4.write(() => out)), () => pull(push, __tsplusTrace)), err => tsplus_module_9.fail(() => err), () => tsplus_module_7.flatMap_(tsplus_module_6.fromEffect(() => push(tsplus_module_5.none)), out => tsplus_module_4.write(() => out)));
}
//# sourceMappingURL=transducePush.mjs.map