@lwhitefox wrote:
I’ve been looking at some sample code from th eFlux model zoo, and I came across something like:
f(x) = x^2 d = (f(i) for i in 1:10)
(this is much simplified to help pose the question). The result indicates that
d
isBase.Generator{UnitRange{Int64},typeof(f)}(f, 1:10)
- I cannot find any documentation ofGenerator
at docs.julialang.org. It is clear that if I applycollect(d)
I get the expected output array (1,4,9,…). However, I could just as easily get that result from using brackets instead of parentheses:d = [f(i) for i in 1:10]
So, what is a Generator, and why would one utilize it rather than directly producing the Array?
Thanks in advance for tips!
Posts: 10
Participants: 6