partition ( ... seq quot: ( ... elt -- ... ? ) -- ... trueseq falseseq )
Factor handbook » The language » Collections » Sequence operations » Sequence combinators

Prev:filter-as ( ... seq quot: ( ... elt -- ... ? ) exemplar -- ... subseq )
Next:count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )


Vocabulary
sequences

Inputs
seqa sequence
quota quotation


Outputs
trueseqa sequence
falseseqa sequence


Word description
Calls a predicate quotation on each element of the input sequence. If the test yields true, the element is added to trueseq; if false, it's added to falseseq.

Examples
USING: prettyprint kernel math sequences ; { 1 2 3 4 5 } [ even? ] partition [ . ] bi@
{ 2 4 } { 1 3 5 }


Definition


: partition
( ... seq quot: ( ... elt -- ... ? ) -- ... trueseq falseseq )
over [ 2selector [ each ] 2dip ] dip [ like ] curry bi@ ;
inline