Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

What is a Base.Generator?

$
0
0

@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 is Base.Generator{UnitRange{Int64},typeof(f)}(f, 1:10) - I cannot find any documentation of Generator at docs.julialang.org. It is clear that if I apply collect(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

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles