sequences.extras: even simpler round-robin.

db4
John Benediktsson 2012-05-31 10:46:42 -07:00
parent 58185a06ce
commit d412364483
1 changed files with 2 additions and 6 deletions

View File

@ -184,12 +184,8 @@ PRIVATE>
: 2count ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ? ) -- ... n )
[ 1 0 ? ] compose 2map-sum ; inline
: max-lengths ( seq -- n )
[ length ] [ max ] map-reduce ;
: round-robin ( seq -- newseq )
[ { } ] [
dup [ max-lengths ] [ length ] bi [ iota ] bi@
[ [ 2array ] with map ] curry map concat swap
[ [ first2 ] dip nth-unsafe ?nth ] curry map sift
[ [ length ] [ max ] map-reduce iota ] keep
[ [ ?nth ] with map ] curry map concat sift
] if-empty ;