File tree Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -72,4 +72,5 @@ IN: sequences.extras.tests
72
72
{ 8 } [ 3 iota dup [ 1 + * ] 2map-sum ] unit-test
73
73
{ 4 } [ "hello" "jello" [ = ] 2count ] unit-test
74
74
75
- { "ADEBFC" } [ { "ABC" "D" "EF" } round-robin ] unit-test
75
+ { { } } [ { } round-robin ] unit-test
76
+ { "ADEBFC" } [ { "ABC" "D" "EF" } round-robin >string ] unit-test
Original file line number Diff line number Diff line change @@ -184,15 +184,12 @@ PRIVATE>
184
184
: 2count ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ? ) -- ... n )
185
185
[ 1 0 ? ] compose 2map-sum ; inline
186
186
187
- :: round-robin-as ( seqs exemplar -- newseq )
188
- seqs length :> len
189
- 0 0 seqs sum-lengths [
190
- f [
191
- drop dup len >= [ drop 1 + 0 ] when
192
- 2dup seqs nth-unsafe ?nth
193
- [ 1 + ] [ dup not ] bi*
194
- ] loop
195
- ] exemplar replicate-as 2nip ;
196
-
197
- : round-robin ( seqs -- newseq )
198
- [ { } ] [ dup first round-robin-as ] if-empty ;
187
+ : max-lengths ( seq -- n )
188
+ [ length ] [ max ] map-reduce ;
189
+
190
+ : round-robin ( seq -- newseq )
191
+ [ { } ] [
192
+ dup [ max-lengths ] [ length ] bi [ iota ] bi@
193
+ [ [ 2array ] with map ] curry map concat swap
194
+ [ [ first2 ] dip nth-unsafe ?nth ] curry map sift
195
+ ] if-empty ;
You can’t perform that action at this time.
0 commit comments