Thanks. I was confused because neither flatten nor Iterators are exported for me. I have to use using Base.Iterators to get it. That’s expected, right?
Like @djsegal, I’ve been struggling to find an efficient idiomatic way to reduce a function over the individual elements of an Array{Array{T}}. Even when the reducing function doesn’t need to allocate, say something like max, I still see quite a bit of allocations.
x = [rand(100) for i in 1:50]
# assuming f itself doesn't allocate - e.g. max
f1(x) = reduce(max, Iterators.flatten(x))
@benchmark f1($x)
# memory estimate: 312.52 KiB
# allocs estimate: 10001
f2(x) = reduce(max, (z for y=x for z=y))
@benchmark f2($x)
# memory estimate: 314.88 KiB
# allocs estimate: 10102
I would appreciate it if anyone could suggest a way to achieve this without allocations. It would be a shame to have to write a for loop.