head* ( seq n -- headseq )
Factor handbook » The language » Collections » Sequence operations » Subsequences and slices

Prev:tail ( seq n -- tailseq )
Next:tail* ( seq n -- tailseq )


Vocabulary
sequences

Inputs
seqa sequence
na non-negative integer


Outputs
headseqa new sequence


Word description
Outputs a new sequence consisting of all elements of seq until the nth element from the end. In other words, it removes the last n elements.

Examples
USING: sequences prettyprint ; { 1 2 3 4 5 6 7 } 2 head* .
{ 1 2 3 4 5 }

When a sequence may not have enough elements:
USING: sequences prettyprint ; { 1 2 } 5 index-or-length head* .
{ }


Errors
Throws an error if the index is out of bounds.

See also
head, head-slice, head-slice*

Definition

: head* ( seq n -- headseq ) from-tail head ;