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

Prev:subseq-as ( from to seq exemplar -- subseq )
Next:tail ( seq n -- tailseq )


Vocabulary
sequences

Inputs and outputs
seqa sequence
na non-negative integer
headseqa new sequence


Word description
Outputs a new sequence consisting of the first n elements of the input sequence.

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

When a sequence may not have enough elements:
USING: sequences prettyprint ; { 1 2 } 5 short head .
{ 1 2 }


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

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

Definition