projects
/
onyx.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ee439d3
)
added: `iter.counter`
author
Brendan Hansen
<brendan.f.hansen@gmail.com>
Fri, 8 Dec 2023 04:32:29 +0000
(22:32 -0600)
committer
Brendan Hansen
<brendan.f.hansen@gmail.com>
Fri, 8 Dec 2023 04:32:29 +0000
(22:32 -0600)
core/container/iter.onyx
patch
|
blob
|
history
diff --git
a/core/container/iter.onyx
b/core/container/iter.onyx
index e37de430441b309d67d6ad7af4da5a3643377587..204c9089dc4f9f9f68aa893107e892d3f28af42f 100644
(file)
--- a/
core/container/iter.onyx
+++ b/
core/container/iter.onyx
@@
-93,6
+93,25
@@
empty :: ($T: type_expr) -> Iterator(T) {
};
}
+
+#doc """
+ Helper function to create an infinite counting iterator.
+
+ Use `start` to configure the starting value.
+
+ Use `type` to configure the type used for the iterator.
+"""
+counter :: (start: type = 0, $type: type_expr = i32) -> Iterator(type) {
+ return generator(
+ &.{ i = start },
+ ctx => {
+ defer ctx.i += 1;
+ return ctx.i, true;
+ }
+ );
+}
+
+
//
// Implicit iterator creation
//