aboutsummaryrefslogtreecommitdiff
path: root/stdlib/integers.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-02-13 15:21:00 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-02-13 15:21:00 -0500
commitc4479e4bd61fb2c68fdac2637a20d6d99f7b9552 (patch)
treed6cc4335d64ad9d8be9e375f6e820cfcccd153df /stdlib/integers.c
parent5be955904682300153af0abdfd6b711b9da2ac8f (diff)
Add Int:onward() iterator
Diffstat (limited to 'stdlib/integers.c')
-rw-r--r--stdlib/integers.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/stdlib/integers.c b/stdlib/integers.c
index 858025fa..835da97b 100644
--- a/stdlib/integers.c
+++ b/stdlib/integers.c
@@ -362,6 +362,14 @@ public PUREFUNC Closure_t Int$to(Int_t first, Int_t last, OptionalInt_t step) {
return (Closure_t){.fn=_next_int, .userdata=range};
}
+public PUREFUNC Closure_t Int$onward(Int_t first, Int_t step) {
+ IntRange_t *range = GC_MALLOC(sizeof(IntRange_t));
+ range->current = first;
+ range->last = NONE_INT;
+ range->step = step;
+ return (Closure_t){.fn=_next_int, .userdata=range};
+}
+
public Int_t Int$from_str(const char *str) {
mpz_t i;
int result;
@@ -575,6 +583,13 @@ public void Int32$deserialize(FILE *in, void *outval, Array_t*, const TypeInfo_t
range->step = step.is_none ? (last >= first ? I_small(1) : I_small(-1)) : KindOfInt##_to_Int(step.i); \
return (Closure_t){.fn=_next_int, .userdata=range}; \
} \
+ public to_attr Closure_t KindOfInt ## $onward(c_type first, c_type step) { \
+ IntRange_t *range = GC_MALLOC(sizeof(IntRange_t)); \
+ range->current = KindOfInt##_to_Int(first); \
+ range->last = NONE_INT; \
+ range->step = KindOfInt##_to_Int(step); \
+ return (Closure_t){.fn=_next_int, .userdata=range}; \
+ } \
public PUREFUNC Optional ## KindOfInt ## _t KindOfInt ## $parse(Text_t text) { \
OptionalInt_t full_int = Int$parse(text); \
if (full_int.small == 0) return (Optional ## KindOfInt ## _t){.is_none=true}; \