# Is this a legal use of Zip?

**URL:** <https://discourse.julialang.org/t/is-this-a-legal-use-of-zip/41703>\
**Category:** General Usage\
**Created:** [June 19, 2020, 12:02am UTC](https://discourse.julialang.org/t/is-this-a-legal-use-of-zip/41703 "2020-06-19T00:02:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [June 19, 2020, 12:02am UTC](https://discourse.julialang.org/t/is-this-a-legal-use-of-zip/41703/1 "2020-06-19T00:02:11Z")

</div>

I would like to create a collection of iterators. Before I start iterating I would like to access individual iterators. Doing that requires accessing the field of Zip. Does this look okay?

```julia
N = 3
it1 = fill(1, N)
it2 = fill(2, N)
z = zip(it1, it2)
@show z.is[1]

```

---

<div class="post-metadata">

**Author:** ![ettersi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ettersi/32/6829_2.png) [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Post date:** [June 19, 2020, 2:51am UTC](https://discourse.julialang.org/t/is-this-a-legal-use-of-zip/41703/2 "2020-06-19T02:51:30Z")

</div>

AFAIK, fields are usually considered an implementation detail and are not part of the API. So your code currently works and will likely continue to work for a long time, but technically it is possible that some future version of Julia changes the internals of `zip` and your code breaks.

I would recommend that instead of passing a `zip()` object, you pass a tuple of iterators and then you only `zip()` them once you start iterating.

```julia
N = 3
it1 = fill(1, N)
it2 = fill(2, N)

iters = (it1,it2)
# Do what you need to do with iters[i], then iterate using
for i in zip(iters...)
    # Work on i
end

```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [June 19, 2020, 2:52am UTC](https://discourse.julialang.org/t/is-this-a-legal-use-of-zip/41703/3 "2020-06-19T02:52:50Z")

</div>

That sounds like good advice.
