deep-nth-of ( nested-seq index-seq -- elt )


Vocabulary
sequences.extras

Inputs
nested-seqa sequence
index-seqa sequence


Outputs
eltan object


Word description
A version of nth-of that drills into a nested seq. Gets element n1 from nested-seq, then element n2 from that result, and so on, where n1, n2, etc come from index-seq. When index-seq is exhausted, the result is put on the stack. Note that this usage of "deep" is different from those in sequences.deep.

Examples
An empty index-seq leaves nested-seq on the stack:
USING: sequences.extras prettyprint ; { 1 2 3 } { } deep-nth-of .
{ 1 2 3 }

An index-seq with one element is the same as calling nth-of with that element:
USING: kernel sequences.extras prettyprint ; "abc" { 1 } deep-nth-of "abc" 1 nth-of = .
t

Multiple elements in index-seq act like repeated calls to nth-of:
USING: sequences.extras prettyprint ; { "zero" { "one-zero" "one-one" } } { 1 1 } deep-nth-of .
"one-one"


Errors
Throws a bounds-error if any of the indices are negative, or greater than or equal to the length of nested-seq (at the corresponding nesting level).

Definition


: deep-nth-of ( nested-seq index-seq -- elt ) [ nth-of ] each ;