selector ( quot -- selector accum )
Factor documentation > Factor handbook > The language > Collections > Sequence operations > Implementing sequence combinators
Prev:collector-for ( quot exemplar -- quot' vec )
Next:selector-for ( quot exemplar -- selector accum )


Vocabulary
sequences

Inputs and outputs
quota quotation with stack effect ( ... elt -- ... ? )
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
IN: sequences

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