Handbook
Glossary
last2 ( seq -- penultimate ultimate )
Factor handbook
»
The language
»
Collections
»
Sequence operations
»
Accessing sequence elements
Prev:
first4 ( seq -- first second third fourth )
Vocabulary
sequences
Inputs
seq
a
sequence
Outputs
penultimate
an
object
ultimate
an
object
Word description
Outputs the last two elements of a sequence.
Errors
Throws an error if the sequence has fewer than two elements.
See also
first
,
first2
,
last
,
but-last
,
but-last-slice
,
rest
,
rest-slice
Definition
USING:
kernel
math
sequences.private
;
IN:
sequences
:
last2
( seq -- penultimate ultimate )
index-of-last
[
[
1
-
]
keep
]
dip
pick
0
<
[
nip
bounds-error
]
[
[
nth-unsafe
]
curry
bi@
]
if
;
inline