sequences.extras: adding flatten1.

db4
John Benediktsson 2012-11-07 17:02:22 -08:00
parent 1d6209e80e
commit f0999e83dc
2 changed files with 13 additions and 1 deletions

View File

@ -166,3 +166,6 @@ IN: sequences.extras.tests
{ { 1 0 0 1 0 0 0 1 0 0 } }
[ 1 { 0 3 7 } 10 0 <array> [ set-nths-unsafe ] keep ] unit-test
{ V{ 1 } } [ 1 flatten1 ] unit-test
{ { 1 2 3 } } [ { 1 2 3 } flatten1 ] unit-test
{ { 1 2 3 { { 4 } } } } [ { 1 { 2 } { 3 { { 4 } } } } flatten1 ] unit-test

View File

@ -1,6 +1,6 @@
USING: accessors arrays assocs fry grouping growable kernel
locals make math math.order math.ranges sequences
sequences.private sorting splitting ;
sequences.deep sequences.private sorting splitting ;
FROM: sequences => change-nth ;
IN: sequences.extras
@ -365,3 +365,12 @@ PRIVATE>
: set-nths-unsafe ( value indices seq -- )
swapd '[ [ _ ] dip _ set-nth-unsafe ] each ; inline
: flatten1 ( obj -- seq )
[
[
dup branch? [
[ dup branch? [ % ] [ , ] if ] each
] [ , ] if
]
] keep dup branch? [ drop f ] unless make ;