]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: adding join-with.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 15 Feb 2018 22:46:19 +0000 (14:46 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 15 Feb 2018 22:46:19 +0000 (14:46 -0800)
extra/sequences/extras/extras-tests.factor
extra/sequences/extras/extras.factor

index 50d2f4118a5a085cef27f4030b631959e6ffc254..15664c64b32990eb877ebdc931ec6804050f4587 100644 (file)
@@ -262,3 +262,7 @@ tools.test vectors vocabs ;
 { { 4 5 6 7 } } [ 8 <iota> [ 4 < ] drop-while >array ] unit-test
 { { 15 16 } } [ { 15 16 } [ 4 < ] drop-while >array ] unit-test
 { { } } [ 3 <iota> [ 4 < ] drop-while >array ] unit-test
+
+{ { } } [ { } ", " join-with ] unit-test
+{ { 1 } } [ { 1 } ", " join-with ] unit-test
+{ { 1 ", " 2 } } [ { 1 2 } ", " join-with ] unit-test
index 83febd65f775f2085d59b840e9ea68c777218f24..5b1e7b43947dfd7dbee71a64e98ba363f667e0fe 100644 (file)
@@ -625,3 +625,8 @@ PRIVATE>
 : drop-while ( ... seq quot: ( ... elt -- ... ? ) -- tail-slice )
     [ '[ @ not ] find drop ] 2keep drop swap
     [ dup length ] unless* tail-slice ; inline
+
+: join-with ( seq glue -- newseq )
+    V{ } clone [
+        [ '[ _ _ push ] ] [ '[ _ push ] ] bi interleave
+    ] keep { } like ;