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

Generators as "Array Initializers" #48623

Closed
uniment opened this issue Feb 10, 2023 · 4 comments
Closed

Generators as "Array Initializers" #48623

uniment opened this issue Feb 10, 2023 · 4 comments
Labels
arrays [a, r, r, a, y, s] design Design of APIs or of the language itself duplicate Indicates similar issues or pull requests feature Indicates new feature / enhancement requests

Comments

@uniment
Copy link

uniment commented Feb 10, 2023

(Related Discourse discussion)

This would be nice:

y = Array{Float64}(i+j for i=1:m, j=1:n)
y == Float64[i+j for i=1:m, j=1:n] # true

Would passing generators to the Array constructor be redundant with comprehensions? Yes. Why request it then? Because a) it'd create consistency with the fact that other similar constructors also accept generators (e.g. Tuple, NamedTuple, Dict, etc.), and b) it creates an idiom for non-standard arrays to be constructed with generators.

@rfourquet
Copy link
Member

rfourquet commented Jun 23, 2023

I would hope to not limit this feature to only generators, but any iterators. It would also provide an idiomatic solution to #47777: Vector{Float64}(rand(2, 2)), or Vector(rand(2, 2)), is probably the most straigthforward way to say "give me a vector out of this matrix".

@uniment
Copy link
Author

uniment commented Jan 31, 2024

any iterators

This seems like a disjoint feature, but maybe not a bad idea? Can you open a separate issue for it?

@vtjnash
Copy link
Member

vtjnash commented Jan 31, 2024

Yes, this is redundant with the definition of collect also, and also that yes we should finally implement this, as we already did for other constructors as you noted

@inkydragon inkydragon added the feature Indicates new feature / enhancement requests label Feb 1, 2024
@nsajko nsajko added arrays [a, r, r, a, y, s] design Design of APIs or of the language itself duplicate Indicates similar issues or pull requests labels Apr 22, 2024
@nsajko
Copy link
Contributor

nsajko commented Apr 22, 2024

dup of #16029

@nsajko nsajko closed this as completed Apr 27, 2024
@nsajko nsajko closed this as not planned Won't fix, can't repro, duplicate, stale Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] design Design of APIs or of the language itself duplicate Indicates similar issues or pull requests feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

5 participants