From c4479e4bd61fb2c68fdac2637a20d6d99f7b9552 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 13 Feb 2025 15:21:00 -0500 Subject: Add Int:onward() iterator --- stdlib/integers.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'stdlib/integers.c') 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}; \ -- cgit v1.2.3