# Difference between Base.product and Iterators.product?

**URL:** <https://discourse.julialang.org/t/difference-between-base-product-and-iterators-product/43263>\
**Category:** New to Julia\
**Created:** [July 17, 2020, 10:10pm UTC](https://discourse.julialang.org/t/difference-between-base-product-and-iterators-product/43263 "2020-07-17T22:10:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Ainsworth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samuel_ainsworth/32/15644_2.png) [@Samuel\_Ainsworth](https://discourse.julialang.org/u/Samuel_Ainsworth)\
**Post date:** [July 17, 2020, 10:10pm UTC](https://discourse.julialang.org/t/difference-between-base-product-and-iterators-product/43263/1 "2020-07-17T22:10:20Z")

</div>

They seem identical down to the documentation:

```julia
help?> Base.product
  product(iters...)

  Return an iterator over the product of several iterators. Each generated element
  is a tuple whose ith element comes from the ith argument iterator. The first
  iterator changes the fastest.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> collect(Iterators.product(1:2, 3:5))
  2×3 Array{Tuple{Int64,Int64},2}:
   (1, 3) (1, 4) (1, 5)
   (2, 3) (2, 4) (2, 5)

help?> Iterators.product
  product(iters...)

  Return an iterator over the product of several iterators. Each generated element
  is a tuple whose ith element comes from the ith argument iterator. The first
  iterator changes the fastest.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> collect(Iterators.product(1:2, 3:5))
  2×3 Array{Tuple{Int64,Int64},2}:
   (1, 3) (1, 4) (1, 5)
   (2, 3) (2, 4) (2, 5)

```

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [July 17, 2020, 10:40pm UTC](https://discourse.julialang.org/t/difference-between-base-product-and-iterators-product/43263/2 "2020-07-17T22:40:51Z")

</div>

Indeed, they are the same:

```julia
julia> @which Base.product(1:2, 3:5)
product(iters...) in Base.Iterators at iterators.jl:898

julia> @which Iterators.product(1:2, 3:5)
product(iters...) in Base.Iterators at iterators.jl:898

```

---

<div class="post-metadata">

**Author:** ![Samuel\_Ainsworth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samuel_ainsworth/32/15644_2.png) [@Samuel\_Ainsworth](https://discourse.julialang.org/u/Samuel_Ainsworth)\
**Post date:** [July 18, 2020, 12:02am UTC](https://discourse.julialang.org/t/difference-between-base-product-and-iterators-product/43263/3 "2020-07-18T00:02:28Z")

</div>

Why the duplication?

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [July 18, 2020, 11:16am UTC](https://discourse.julialang.org/t/difference-between-base-product-and-iterators-product/43263/4 "2020-07-18T11:16:18Z")

</div>

They’re not duplicated:

```julia
julia> Base.product === Iterators.product
true

```

Given that I use the 3-equals version, that means they are literally the same thing.

What’s happening is illustrated by this example:

```julia
julia> module Outer

       module Inner
       export myprod
       myprod(x, y) = x*y
       end

       using .Inner
       export Inner
       end
Main.Outer

julia> using .Outer

julia> Outer.myprod === Inner.myprod
true

```

But `myprod` itself is not visible without scoping:

```julia
julia> myprod
ERROR: UndefVarError: myprod not defined

```
