import * as tsplus_module_1 from "@effect/core/stream/Channel/operations/pipeTo";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/drop";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/isEmpty";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_5 from "@effect/core/stream/Channel/operations/identity";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/zipRight";
import * as tsplus_module_7 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_8 from "@effect/core/stream/Channel/operations/unit";
import * as tsplus_module_9 from "@effect/core/stream/Channel/operations/readWith";
import { concreteStream, StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
/**
 * Drops the specified number of elements from this stream.
 *
 * @tsplus fluent ets/Stream drop
 */

export function drop_(self, n, __tsplusTrace) {
  void 0;
  return new StreamInternal(tsplus_module_1.pipeTo_(self.channel, () => loop(n)));
}
/**
 * Drops the specified number of elements from this stream.
 *
 * @tsplus static ets/Stream/Aspects drop
 */

export const drop = (n, __tsplusTrace) => self => drop_(self, n, __tsplusTrace);

function loop(r) {
  return tsplus_module_9.readWith(chunk => {
    const dropped = tsplus_module_2.drop_(chunk, r);
    const leftover = Math.max(0, r - chunk.length);
    const more = tsplus_module_3.isEmpty(chunk) || leftover > 0;
    return more ? loop(leftover) : tsplus_module_6.zipRight_(tsplus_module_4.write(() => dropped), () => tsplus_module_5.identity());
  }, err => tsplus_module_7.fail(() => err), () => tsplus_module_8.unit);
}
//# sourceMappingURL=drop.mjs.map