import * as tsplus_module_1 from "@effect/core/stream/Channel/MergeStrategy";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/writeChunk";
import * as tsplus_module_3 from "@effect/core/stream/Channel/operations/concatMap";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/mergeMap";
import { concreteStream, StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
/**
 * Maps each element of this stream to another stream and returns the
 * non-deterministic merge of those streams, executing up to `n` inner streams
 * concurrently. When a new stream is created from an element of the source
 * stream, the oldest executing stream is cancelled. Up to `bufferSize`
 * elements of the produced streams may be buffered in memory by this
 * operator.
 *
 * @tsplus fluent ets/Stream flatMapParSwitch
 */

export function flatMapParSwitch_(self, n, f, bufferSize = 16, __tsplusTrace) {
  void 0;
  return new StreamInternal(tsplus_module_4.mergeMap_(tsplus_module_3.concatMap_(self.channel, tsplus_module_2.writeChunk), n, a => {
    const stream = f(a);
    void 0;
    return stream.channel;
  }, bufferSize, tsplus_module_1.BufferSliding));
}
/**
 * Maps each element of this stream to another stream and returns the
 * non-deterministic merge of those streams, executing up to `n` inner streams
 * concurrently. When a new stream is created from an element of the source
 * stream, the oldest executing stream is cancelled. Up to `bufferSize`
 * elements of the produced streams may be buffered in memory by this
 * operator.
 *
 * @tsplus static ets/Stream/Aspects flatMapParSwitch
 */

export const flatMapParSwitch = (n, f, bufferSize = 16, __tsplusTrace) => self => flatMapParSwitch_(self, n, f, bufferSize, __tsplusTrace);
//# sourceMappingURL=flatMapParSwitch.mjs.map