I have a complicated piece of code, with a fragment like:
prod(i for i in 1:10 if i > 10)
The product may or may not be empty, depending on circumstances. When it is empty, Julia gives an error:
ArgumentError: reducing over an empty collection is not allowed
If I have to check for the emptiness myself it will complicate my code significantly. I would like
prod to return 1 instead. I think the problem here is that
prod cannot infer the eltype of the iterator when it is empty.
Is there a way to deal with this?
Oh, this also does not work:
prod(i::Int for i in 1:10 if i > 10)