cut ( seq n -- before after )
Factor handbook > The language > Collections > Sequence operations > Subsequences and slices

Prev:unclip-last ( seq -- butlast last )
Next:cut* ( seq n -- before after )


Inputs and outputs
seqa sequence
na non-negative integer
beforea sequence
aftera sequence

Word description
Outputs a pair of sequences, where before consists of the first n elements of seq, while after holds the remaining elements. Both output sequences have the same type as seq.

Since this word copies the entire tail of the sequence, it should not be used in a loop. If this is important, consider using cut-slice instead, since it returns a slice for the tail instead of copying.

See also
cut*, cut-slice


: cut ( seq n -- before after ) [ head ] [ tail ] 2bi ;