# Iterator tool similar to zip (mesh?)

**URL:** <https://discourse.julialang.org/t/iterator-tool-similar-to-zip-mesh/77137>\
**Category:** General Usage\
**Tags:** iterators, functional\
**Created:** [February 26, 2022, 9:38pm UTC](https://discourse.julialang.org/t/iterator-tool-similar-to-zip-mesh/77137 "2022-02-26T21:38:32Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![reinermartin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/reinermartin/32/25574_2.png) [@reinermartin](https://discourse.julialang.org/u/reinermartin)\
**Post date:** [February 28, 2022, 3:38pm UTC](https://discourse.julialang.org/t/iterator-tool-similar-to-zip-mesh/77137/21 "2022-02-28T15:38:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 28, 2022, 3:48pm UTC](https://discourse.julialang.org/t/iterator-tool-similar-to-zip-mesh/77137/22 "2022-02-28T15:48:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [February 28, 2022, 7:18pm UTC](https://discourse.julialang.org/t/iterator-tool-similar-to-zip-mesh/77137/23 "2022-02-28T19:18:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [February 28, 2022, 9:35pm UTC](https://discourse.julialang.org/t/iterator-tool-similar-to-zip-mesh/77137/24 "2022-02-28T21:35:50Z")

</div>

```julia

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

```

[Previous page](https://discourse.julialang.org/t/iterator-tool-similar-to-zip-mesh/77137.md?page=1)
