import * as tsplus_module_1 from "@effect/core/stream/Stream/operations/suspend";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/range";
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 { DEFAULT_CHUNK_SIZE } from "@effect/core/stream/Stream/definition";
import { StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
/**
 * Constructs a stream from a range of integers (lower bound included, upper
 * bound not included).
 *
 * @tsplus static ets/Stream/Ops range
 */

export function range(min, max, chunkSize = DEFAULT_CHUNK_SIZE, __tsplusTrace) {
  return tsplus_module_1.suspend(() => new StreamInternal(go(min, max, chunkSize)), __tsplusTrace);
}

function go(min, max, chunkSize) {
  const remaining = max - min;
  return remaining > chunkSize ? tsplus_module_4.zipRight_(tsplus_module_3.write(() => tsplus_module_2.range(min, min + chunkSize - 1)), () => go(min + chunkSize, max, chunkSize)) : tsplus_module_3.write(() => tsplus_module_2.range(min, min + remaining - 1));
}
//# sourceMappingURL=range.mjs.map