Rebol Programming/collect

From Wikibooks, open books for an open world
Jump to navigation Jump to search

USAGE:[edit | edit source]

COLLECT body /into output 

DESCRIPTION:[edit | edit source]

Evaluates a block, storing values via KEEP function, and returns block of collected values.

COLLECT is a function value.

ARGUMENTS[edit | edit source]

  • body -- Block to evaluate (Type: block)

REFINEMENTS[edit | edit source]

  • /into -- Insert into a buffer instead (returns position after insert)
    • output -- The buffer series (modified) (Type: series)

SOURCE CODE[edit | edit source]

collect: func [
    {Evaluates a block, storing values via KEEP function, and returns block of collected values.} 
    body [block!] "Block to evaluate" 
    /into {Insert into a buffer instead (returns position after insert)} 
    output [series!] "The buffer series (modified)"
][
    unless output [output: make block! 16] 
    do make function! [keep] copy/deep body make function! [value /only] copy/deep [
        output: either only [insert/only output :value] [insert output :value] 
        :value
    ] 
    either into [output] [head output]
]