Factor Documentation
|
Home
|
Glossary
|
Search
factorcode.org
?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
n
an integer
seq
a
sequence
elt/f
an 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