| 1694 | * @since 2.0.0 |
| 1695 | */ |
| 1696 | export const range = ( |
| 1697 | min: number, |
| 1698 | max: number, |
| 1699 | chunkSize = Channel.DefaultChunkSize |
| 1700 | ): Stream<number> => |
| 1701 | min > max ? empty : fromPull(Effect.sync(() => { |
| 1702 | const size = Count.normalizeNonEmpty(chunkSize) |
| 1703 | let start = min |
| 1704 | let done = false |
| 1705 | return Effect.suspend(() => { |
| 1706 | if (done) return Cause.done() |
| 1707 | const remaining = max - start + 1 |
| 1708 | if (remaining > size) { |
| 1709 | const chunk = Arr.range(start, start + size - 1) |
| 1710 | start += size |
| 1711 | return Effect.succeed(chunk) |
| 1712 | } |
| 1713 | const chunk = Arr.range(start, start + remaining - 1) |
| 1714 | done = true |
| 1715 | return Effect.succeed(chunk) |
| 1716 | }) |
| 1717 | })) |
| 1718 | |
| 1719 | /** |
| 1720 | * The stream that never produces any value or fails with any error. |