sequences.extras: adding join-with-as, test with strings.
parent
05df842e85
commit
fb0a6c6c5e
|
@ -266,3 +266,8 @@ tools.test vectors vocabs ;
|
||||||
{ { } } [ { } ", " join-with ] unit-test
|
{ { } } [ { } ", " join-with ] unit-test
|
||||||
{ { 1 } } [ { 1 } ", " join-with ] unit-test
|
{ { 1 } } [ { 1 } ", " join-with ] unit-test
|
||||||
{ { 1 ", " 2 } } [ { 1 2 } ", " 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
|
||||||
|
|
|
@ -626,6 +626,11 @@ PRIVATE>
|
||||||
[ '[ @ not ] find drop ] 2keep drop swap
|
[ '[ @ not ] find drop ] 2keep drop swap
|
||||||
[ dup length ] unless* tail-slice ; inline
|
[ 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 )
|
: join-with ( seq glue -- newseq )
|
||||||
[ dup length dup 1 - + 0 max ] dip <array>
|
over join-with-as ;
|
||||||
[ '[ 2 * _ set-nth-unsafe ] each-index ] keep ;
|
|
||||||
|
|
Loading…
Reference in New Issue