How to lazily `collect(zip(fn(a), b))` for some function `fn`?

I want to lazily `collect` a `zip` iterator. See MWE below where I applied `pointer.` to `a` before using a `zip` and `collect`, but `pointer.(a)` allocated a new vector, so I don’t want that. Is there a way to lazily do `pointer.(a)` so I dont’ have to create a new vector first but still end up with `ptra` being a vector of tuples?

``````a = rand([randstring(8) for i = 1_000_000], 100_000_000)
b = rand(100_000_000)
c = similar(b)
ptra = collect(zip(pointer.(a), b, c))
``````
``````julia> a = [1,2,3]; b = copy(a); c = copy(a);

julia> collect(zip(log.(a), b, c))
3-element Array{Tuple{Float64,Int64,Int64},1}:
(0.0, 1, 1)
(0.693147, 2, 2)
(1.09861, 3, 3)

julia> map((a,b,c)->(log(a),b,c), a, b, c)
3-element Array{Tuple{Float64,Int64,Int64},1}:
(0.0, 1, 1)
(0.693147, 2, 2)
(1.09861, 3, 3)

julia> collect((log(x),y,z) for (x,y,z) in zip(a,b,c))
3-element Array{Tuple{Float64,Int64,Int64},1}:
(0.0, 1, 1)
(0.693147, 2, 2)
(1.09861, 3, 3)

julia> it = ((log(x),y,z) for (x,y,z) in zip(a,b,c))
Base.Generator{Base.Iterators.Zip{Array{Int64,1},Base.Iterators.Zip2{Array{Int64,1},Array{Int64,1}}},##40#41}(#40, Base.Iterators.Zip{Array{Int64,1},Base.Iterators.Zip2{Array{Int64,1},Array{Int64,1}}}([1, 2, 3], Base.Iterators.Zip2{Array{Int64,1},Array{Int64,1}}([1, 2, 3], [1, 2, 3])))

julia> collect(it)
3-element Array{Tuple{Float64,Int64,Int64},1}:
(0.0, 1, 1)
(0.693147, 2, 2)
(1.09861, 3, 3)
``````
3 Likes

I feel dumb now. Maybe others will have the same question…