aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/iterator.gleam17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam
index 33ff8d0..690d66e 100644
--- a/src/gleam/iterator.gleam
+++ b/src/gleam/iterator.gleam
@@ -176,3 +176,20 @@ pub fn cycle(iterator: Iterator(a)) -> Iterator(a) {
|> do_cycle(_, iterator)
|> opaque
}
+
+fn do_range(current, limit, inc) -> fn() -> Action(Int) {
+ case current == limit {
+ True -> fn() { Stop }
+ False -> fn() { Continue(current, do_range(current + inc, limit, inc)) }
+ }
+}
+
+// TODO: document
+pub fn range(from start, to stop) -> Iterator(Int) {
+ case start < stop {
+ True -> 1
+ False -> -1
+ }
+ |> do_range(start, stop, _)
+ |> opaque
+}