"use strict"
var __createBinding =
  (this && this.__createBinding) ||
  (Object.create
    ? function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        Object.defineProperty(o, k2, {
          enumerable: true,
          get: function () {
            return m[k]
          }
        })
      }
    : function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        o[k2] = m[k]
      })
var __setModuleDefault =
  (this && this.__setModuleDefault) ||
  (Object.create
    ? function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v })
      }
    : function (o, v) {
        o["default"] = v
      })
var __importStar =
  (this && this.__importStar) ||
  function (mod) {
    if (mod && mod.__esModule) return mod
    var result = {}
    if (mod != null)
      for (var k in mod)
        if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
          __createBinding(result, mod, k)
    __setModuleDefault(result, mod)
    return result
  }
Object.defineProperty(exports, "__esModule", { value: true })
exports.range = void 0
// tracing: off
const A = __importStar(require("../../Collections/Immutable/Chunk"))
const Function_1 = require("../../Function")
const O = __importStar(require("../../Option"))
const T = __importStar(require("../_internal/effect"))
const M = __importStar(require("../_internal/managed"))
const Ref = __importStar(require("../_internal/ref"))
const definitions_1 = require("./definitions")
/**
 * Constructs a stream from a range of integers (lower bound included, upper bound not included)
 */
function range(min, max, chunkSize = definitions_1.DefaultChunkSize) {
  const pull = (ref) =>
    T.map_(
      T.tap_(
        T.bind_(T.do, "start", () => Ref.getAndUpdate_(ref, (_) => _ + chunkSize)),
        ({ start }) => T.when_(T.fail(O.none), () => start >= max)
      ),
      ({ start }) => A.range(start, Math.min(start + chunkSize, max - 1))
    )
  return new definitions_1.Stream(M.map_(Ref.makeManagedRef(min), pull))
}
exports.range = range
//# sourceMappingURL=range.js.map
