interleaved-as ( seq glue exemplar -- newseq )


Vocabulary
sequences.extras

Inputs
seqa sequence
gluean object
exemplaran object


Outputs
newseqa sequence


Word description
Insert glue between every pair of elements in seq. Resulting sequence will be the same class as exemplar.

Definition


:: interleaved-as ( seq glue exemplar -- newseq )
seq length dup 1 - + 0 max exemplar new-sequence
:> newseq seq [ 2 * newseq set-nth-unsafe ] each-index
seq length 1 -
[ 2 * 1 + glue swap newseq set-nth-unsafe ] each-integer
newseq ;