From d08daa5a6240ab23119539d5724e0824482fab18 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 8 Apr 2023 16:57:18 +0200 Subject: [PATCH] more iterator functions --- iter.spl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/iter.spl b/iter.spl index c5fd225..be56ef5 100644 --- a/iter.spl +++ b/iter.spl @@ -1,6 +1,15 @@ construct _Iter { ; + next-chunk { [item] | with amount this ; + def i 0 =i + def arr amount anew =arr + while { i amount lt } { + (this:next i arr:set;) + i ++ =i + } + arr + } foreach { | with callable this ; def itm while { this:next dup =itm null eq not } { @@ -64,6 +73,14 @@ construct _Iter { enumerate { EnumerationIter | with this ; this EnumerationIter:new } + nth { item | with idx this ; + idx -- =idx + while { idx 0 gt } { + this:next; + idx -- =idx + } + this:next + } } construct MapIter {