{ { 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
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
: 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 ;