{ { } } [ { } ", " join-with ] unit-test
{ { 1 } } [ { 1 } ", " join-with ] unit-test
{ { 1 ", " 2 } } [ { 1 2 } ", " join-with ] unit-test
+{ "" } [ "" CHAR: _ join-with ] unit-test
+{ "a" } [ "a" CHAR: _ join-with ] unit-test
+{ "a_b" } [ "ab" CHAR: _ join-with ] unit-test
+{ "a_b_c" } [ "abc" CHAR: _ join-with ] unit-test
+{ "a_b_c_d" } [ "abcd" CHAR: _ join-with ] unit-test
[ '[ @ not ] find drop ] 2keep drop swap
[ dup length ] unless* tail-slice ; inline
+:: join-with-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 ;
+
: join-with ( seq glue -- newseq )
- [ dup length dup 1 - + 0 max ] dip <array>
- [ '[ 2 * _ set-nth-unsafe ] each-index ] keep ;
+ over join-with-as ;