Does prod(f,itr)
short-circuit if itr
contains 0
?
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.
Yet a version of mapreduce
which checks the accumulator for a specific value and returns early upon encountering it could be useful.
2 Likes