selector ( quot -- selector accum )
Factor handbook » The language » Collections » Sequence operations » Implementing sequence combinators

Prev:collector-as ( quot exemplar -- quot' vec )
Next:selector-as ( quot exemplar -- selector accum )


Vocabulary
sequences

Inputs
quota quotation with stack effect ( ... elt -- ... ? )


Outputs
selectora quotation with stack effect ( ... elt -- ... )
accuma vector


Word description
Creates a new vector to accumulate the values which return true for a predicate. Returns a new quotation which accepts an object to be tested and stored in the collector if the test yields true. The collector is left on the stack for convenience.

Examples
! Find all the even numbers: USING: prettyprint sequences math kernel ; 10 <iota> [ even? ] selector [ each ] dip .
V{ 0 2 4 6 8 }


Notes
Used to implement the filter word. Compare this word with collector, which is an unfiltering version.

Definition

: selector ( quot -- selector accum ) V{ } selector-as ; inline