}
{ $description "Calls " { $snippet "quot" } " on each element of the sequence until each call yields " { $link f } " in succession." } ;
-HELP: circular-while*
+HELP: circular-loop
{ $values
{ "circular" circular }
{ "quot" quotation }
}
-{ $description "Calls " { $snippet "quot" } " on each element of the sequence until one call yields " { $link f } "." } ;
+{ $description "Calls " { $snippet "quot" } " on each element of the sequence until one call yields " { $link f } "." }
+{ $notes "This rotates the " { $link circular } " object after each call, so the next element to be applied will always be the first element." } ;
ARTICLE: "circular" "Circular sequences"
"The " { $vocab-link "circular" } " vocabulary implements the " { $link "sequence-protocol" } " to allow an arbitrary start index and wrap-around indexing." $nl
growing-circular-push
}
"Iterating over a circular until a stop condition:"
-{ $subsections circular-while circular-while* } ;
+{ $subsections circular-while circular-loop } ;
ABOUT: "circular"
[ V{ 1 2 3 1 2 } ] [
{ 1 2 3 } <circular> V{ } [
- [ [ push ] [ length 5 < ] bi ] curry circular-while*
+ [ [ push ] [ length 5 < ] bi ] curry circular-loop
] keep
] unit-test
[ V{ 1 } ] [
{ 1 2 3 } <circular> V{ } [
- [ push f ] curry circular-while*
+ [ push f ] curry circular-loop
] keep
] unit-test
: circular-while ( ... circular quot: ( ... obj -- ... ? ) -- ... )
[ clone ] dip [ <circular-iterator> ] dip (circular-while) ; inline
-: circular-while* ( ... circular quot: ( ... obj -- ... ? ) -- ... )
+: circular-loop ( ... circular quot: ( ... obj -- ... ? ) -- ... )
[ clone ] dip '[ [ first @ ] [ rotate-circular ] bi ] curry loop ; inline