Iterator tool similar to zip (mesh?)

…and Rust isn’t exactly a functional programming language. One of the things which attract me to Julia are its pragmatic functional features.

Very interesting that Rust has a IterTools package with such functionality, however, if I am not reading wrong it seems like it would be kinda hard to extend it to work on three iterators, or any number that is not a power of two.

As a Haskell lover, I have to say that the comparison is a little unfair: Haskell does not have a specific function for this (yes, because it is too simple to do that with what you have), but it is so simple to implement because Haskell is by default lazy, so there is no much distinction anywhere between a finite or infinite list, both are just evaluated up to the point you need.

“Interleave” sounds indeed like a good name for this operation.


using IterTools
function interleave(itrs, v=[])
    f, r = zip(imap(firstrest, itrs)...)
    append!(v, f)
    r==() && return v
    interleave(filter(!isempty, r), v)
end