] with each >array
] unit-test
+[ V{ 1 2 3 } ] [
+ { 1 2 3 } <circular> V{ } [
+ [ push f ] curry circular-while
+ ] keep
+] unit-test
+
+CONSTANT: test-sequence1 { t f f f }
+[ V{ 1 2 3 1 } ] [
+ { 1 2 3 } <circular> V{ } [
+ [ [ push ] [ length 1 - test-sequence1 nth ] bi ] curry circular-while
+ ] keep
+] unit-test
+
+CONSTANT: test-sequence2 { t f t t f f t t t f f f }
+[ V{ 1 2 3 1 2 3 1 2 3 1 2 3 } ] [
+ { 1 2 3 } <circular> V{ } [
+ [ [ push ] [ length 1 - test-sequence2 nth ] bi ] curry circular-while
+ ] keep
+] unit-test
+
[ V{ 1 2 3 1 2 } ] [
{ 1 2 3 } <circular> V{ } [
[ [ push ] [ length 5 < ] bi ] curry circular-while*
{ circular read-only } { n integer } { last-start integer } ;
: <circular-iterator> ( circular -- obj )
- 0 0 circular-iterator boa ; inline
+ 0 -1 circular-iterator boa ; inline
<PRIVATE
: (circular-while) ( ... iterator quot: ( ... obj -- ... ? ) -- ... )
[ [ [ n>> ] [ circular>> ] bi nth ] dip call ] 2keep
rot [ [ dup n>> >>last-start ] dip ] when
- over [ n>> ] [ [ last-start>> ] [ circular>> length ] bi + 1 - ] bi = [
+ over [ n>> ] [ [ last-start>> ] [ circular>> length ] bi + ] bi = [
2drop
] [
[ [ 1 + ] change-n ] dip (circular-while)