Sequence combinators
Factor handbook » The language » Collections » Sequence operations

Prev:Accessing sequence elements
Next:Adding and removing sequence elements


Iteration:
Image
each ( ... seq quot: ( ... x -- ... ) -- ... )

Image
each-index ( ... seq quot: ( ... elt index -- ... ) -- ... )

Image
reduce ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... result )

Image
interleave ( ... seq between quot: ( ... elt -- ... ) -- ... )


Mapping:
Image
map ( ... seq quot: ( ... elt -- ... newelt ) -- ... newseq )

Image
map-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )

Image
map-index ( ... seq quot: ( ... elt index -- ... newelt ) -- ... newseq )

Image
map-index-as ( ... seq quot: ( ... elt index -- ... newelt ) exemplar -- ... newseq )

Image
map-reduce ( ..a seq map-quot: ( ..a elt -- ..a intermediate ) reduce-quot: ( ..a prev intermediate -- ..a next ) -- ..a result )

Image
accumulate ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final newseq )

Image
accumulate-as ( ... seq identity quot: ( ... prev elt -- ... next ) exemplar -- ... final newseq )

Image
accumulate* ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... newseq )

Image
accumulate*-as ( ... seq identity quot: ( ... prev elt -- ... next ) exemplar -- ... newseq )


Filtering:
Image
filter ( ... seq quot: ( ... elt -- ... ? ) -- ... subseq )

Image
filter-as ( ... seq quot: ( ... elt -- ... ? ) exemplar -- ... subseq )

Image
partition ( ... seq quot: ( ... elt -- ... ? ) -- ... trueseq falseseq )


Counting:
Image
count ( ... seq quot: ( ... elt -- ... ? ) -- ... n )


Superlatives with min and max:
Image
minimum ( seq -- elt )

Image
minimum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )

Image
maximum ( seq -- elt )

Image
maximum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )

Image
shorter ( seq1 seq2 -- seq )

Image
longer ( seq1 seq2 -- seq )

Image
shorter? ( seq1 seq2 -- ? )

Image
longer? ( seq1 seq2 -- ? )

Image
shortest ( seqs -- elt )

Image
longest ( seqs -- elt )


Generating:
Image
replicate ( ... len quot: ( ... -- ... newelt ) -- ... newseq )

Image
replicate-as ( ... len quot: ( ... -- ... newelt ) exemplar -- ... newseq )

Image
produce ( ..a pred: ( ..a -- ..b ? ) quot: ( ..b -- ..a obj ) -- ..b seq )

Image
produce-as ( ..a pred: ( ..a -- ..b ? ) quot: ( ..b -- ..a obj ) exemplar -- ..b seq )


Math:
Image
sum ( seq -- n )

Image
product ( seq -- n )


Testing if a sequence contains elements satisfying a predicate:
Image
any? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )

Image
all? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )

Image
none? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )


Related Articles
Image Pair-wise sequence combinators
Image Triple-wise sequence combinators