Destructive sequence operations - Factor Documentation (original) (raw)

Destructive sequence operations
Factor handbook » The language » Collections » Sequence operations

Prev: Groups and clumps
Next: Treating sequences as stacks

Many operations have destructive variants that side effect an input sequence, instead of creating a new sequence:

Constructive Destructive
suffix suffix!
remove remove!
remove-eq remove-eq!
remove-nth remove-nth!
reverse reverse!
append append!
map map!
accumulate accumulate!
accumulate* accumulate*!
filter filter!

Changing elements:
map! ( ... seq quot: ( ... elt -- ... newelt ) -- ... seq )
accumulate! ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... final seq )
accumulate*! ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... seq )
change-nth ( ..a i seq quot: ( ..a elt -- ..b newelt ) -- ..b )

Deleting elements:

remove! ( elt seq -- seq )

remove-eq! ( elt seq -- seq )
remove-nth! ( n seq -- seq )
delete-slice ( from to seq -- )
delete-all ( seq -- )
filter! ( ... seq quot: ( ... elt -- ... ? ) -- ... seq )

Adding elements:

suffix! ( seq elt -- seq )

append! ( seq1 seq2 -- seq1 )

Other destructive words:

reverse! ( seq -- seq )

move ( to from seq -- )
exchange ( m n seq -- )
copy ( src i dst -- )

Related Articles
When to use destructive operations
Treating sequences as stacks

See also
set-nth, push, push-all, pop, pop*