?nth ( n seq -- elt/f )
Factor documentation > Factor handbook > The language > Collections > Sequence operations > Accessing sequence elements
Next:first ( seq -- first )


Vocabulary
sequences

Inputs and outputs
nan integer
seqa sequence
elt/fan object or f


Word description
A forgiving version of nth. If the index is out of bounds, or if the sequence is f, simply outputs f.

Definition
USING: kernel sequences.private ;

IN: sequences

: ?nth ( n seq -- elt/f )
2dup bounds-check? [ nth-unsafe ] [ 2drop f ] if ; inline