# Iterator product

**URL:** <https://discourse.julialang.org/t/iterator-product/17018>\
**Category:** New to Julia\
**Created:** [October 31, 2018, 6:00pm UTC](https://discourse.julialang.org/t/iterator-product/17018 "2018-10-31T18:00:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlivierHnt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivierhnt/32/6227_2.png) [@OlivierHnt](https://discourse.julialang.org/u/OlivierHnt)\
**Post date:** [October 31, 2018, 6:00pm UTC](https://discourse.julialang.org/t/iterator-product/17018/1 "2018-10-31T18:00:38Z")

</div>

Good afternoon,

I wish to use `collect(Iterators.product(iter, ...))` but I need the input to be adaptive. For example suppose `n=2`, then I want the code to run

```julia
iter = 0:3
collect(Iterators.product(iter, iter))

```

and if `n=5`, then

```julia
iter = 0:3
collect(Iterators.product(iter, iter, iter, iter, iter))

```

I tried to use different things, for instance `repeat`, but nothing worked. Any suggestions ?

Thank you very much for your help! 🙂

---

<div class="post-metadata">

**Author:** ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)\
**Post date:** [October 31, 2018, 6:01pm UTC](https://discourse.julialang.org/t/iterator-product/17018/2 "2018-10-31T18:01:49Z")

</div>

You should be able to say `collect(Iterators.product(Iterators.repeated(iter, n)...))`.

(And if you `using .Iterators`, then you can say this more tersely as `collect(product(repeated(iter, n)...))`.

---

<div class="post-metadata">

**Author:** ![OlivierHnt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivierhnt/32/6227_2.png) [@OlivierHnt](https://discourse.julialang.org/u/OlivierHnt)\
**Post date:** [October 31, 2018, 6:03pm UTC](https://discourse.julialang.org/t/iterator-product/17018/3 "2018-10-31T18:03:05Z")

</div>

Oh I see, I did not use `repeat` through `Iterator`! Thank you
