follow ( ... obj quot: ( ... prev -- ... result/f ) -- ... seq )


Vocabulary
sequences

Inputs
objan object
quota quotation with stack effect ( ... prev -- ... result/f )


Outputs
seqa sequence


Word description
Outputs a sequence containing the input object and all of the objects generated by successively feeding the result of the quotation called on the input object to the quotation recursively. Objects yielded by the quotation are added to the output sequence until the quotation yields f, at which point the recursion terminates.

Examples
Get random numbers until zero is reached:
USING: random sequences prettyprint math ; 100 [ random [ f ] when-zero ] follow .
{ 100 86 34 32 24 11 7 2 }


Definition


: follow
( ... obj quot: ( ... prev -- ... result/f ) -- ... seq )
[ dup ] swap [ keep ] curry produce nip ; inline