# Short-circuit prod(f,itr) if itr contains 0?

**URL:** <https://discourse.julialang.org/t/short-circuit-prod-f-itr-if-itr-contains-0/4917>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 18, 2017, 9:01am UTC](https://discourse.julialang.org/t/short-circuit-prod-f-itr-if-itr-contains-0/4917 "2017-07-18T09:01:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [July 18, 2017, 9:01am UTC](https://discourse.julialang.org/t/short-circuit-prod-f-itr-if-itr-contains-0/4917/1 "2017-07-18T09:01:13Z")

</div>

Does `prod(f,itr)` short-circuit if `itr` contains `0`?

---

<div class="post-metadata">

**Author:** ![Evey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evey/32/214967_2.png) [@Evey](https://discourse.julialang.org/u/Evey)\
**Post date:** [July 18, 2017, 9:34am UTC](https://discourse.julialang.org/t/short-circuit-prod-f-itr-if-itr-contains-0/4917/2 "2017-07-18T09:34:04Z")

</div>

No. Currently it just uses `reduce` with `*`. You can try it with `@time prod(0:1_000_000)`, and see that it takes significantly longer than `@time prod(0:100_000)`.

But I’m not sure if it should? There would be some overhead to checking for `iszero`, and it wouldn’t work for iterables of types where `iszero` can’t be sensibly defined, like a string.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 18, 2017, 10:14am UTC](https://discourse.julialang.org/t/short-circuit-prod-f-itr-if-itr-contains-0/4917/3 "2017-07-18T10:14:58Z")

</div>

> [@Evey](#):
>
> There would be some overhead to checking for iszero, and it wouldn’t work for iterables of types where iszero can’t be sensibly defined, like a string.

Yet a version of `mapreduce` which checks the accumulator for a specific value and returns early upon encountering it could be useful.
