
10 Apr
2007
10 Apr
'07
7:26 p.m.
"Bas van Dijk"
Hello,
For my own exercise I'm writing a function 'weave' that "weaves" a list of lists together. For example:
weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2] weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1]
[...]
So I'm wondering if 'weave' can be defined more "elegantly" (better readable, shorter, more efficient, etc.)?
I don't know about your other criteria, but this is shorter: weave [] = [] weave ([]:_) = [] weave ((x:xs):others) = x : weave (others ++ [xs]) It's also lazy:
take 12 $ weave [[1..], [100..], [200..]] [1,100,200,2,101,201,3,102,202,4,103,203]