Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Superfluous collect in "Introduction to Julia" #2

Open
jlapeyre opened this issue Oct 20, 2023 · 0 comments
Open

Superfluous collect in "Introduction to Julia" #2

jlapeyre opened this issue Oct 20, 2023 · 0 comments

Comments

@jlapeyre
Copy link

The example code following

data = collect(range(0.0, 5.0, 100))

works just as well with data = range(0.0, 5.0, 100), which does not materialize all of the elements. In the latter, the elements in data are generated as needed. This is idiomatic/recommended.

This same observation may apply in a couple of other places in the introduction.

If you are actually concerned about memory or performance in a particular instance it's worth benchmarking lazy vs. materialized array because the results might not be what you expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant