I have an iterator, and I wish to convert it into an array. Normally, I could just do:
vec = [i for i in iter]
or
vec = map(i -> i, iter]
but now my iterator happens to contain tuples (of numbers). It is generated as:
iter = Iterators.product(1:10,1:10,1:10)
and if I now do either one of
vec = [i for i in iter]
vec = map(i -> i, iter]
I get a 3d array, which is awkward, since I want a vector. The only way I have found is to do:
vec = [];
foreach(i -> push!(vec,i), iter)
but this feels a little bit more convoluted than what should be possible. It feels like I am missing something here, which I don’t understand, which is why the first two approaches doesn’t work.
Also note that the reason why collecting that iterator returns an array of size (10, 10, 10) is, that the Iterator returned by Iterators.product defines size():