prefix ( seq elt -- newseq )
Factor documentation > Factor handbook > The language > Collections > Sequence operations > Adding and removing sequence elements
Next:suffix ( seq elt -- newseq )


Vocabulary
sequences

Inputs and outputs
seqa sequence
eltan object
newseqa sequence


Word description
Outputs a new sequence obtained by adding elt at the beginning of seq.

Errors
Throws an error if the type of elt is not permitted in sequences of the same class as seq1.

Examples
USING: prettyprint sequences ; { 1 2 3 } 0 prefix .
{ 0 1 2 3 }


See also
push, suffix

Definition
USING: kernel math sequences.private ;

IN: sequences

: prefix ( seq elt -- newseq )
over [ over length 1 + ] dip
[ [ 0 swap set-nth-unsafe ] keep [ 1 swap copy ] keep ]
new-like ;