sequences.extras: adding flatten1.
parent
1d6209e80e
commit
f0999e83dc
|
@ -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
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue