-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
change set constructor to accept iterables? #4996
Comments
Writing Set[1,2,3] would be an alternative syntax. It's a slight clash with the Int[1,2,3] syntax but I believe DataArrays may already be doing something along these lines. Perhaps we should formalize the approach as a way of constructing a collection from its elements, where for non-collection types it indicates an Array element type. We probably need a Collection abstract type in Base at this point.
|
It holds a certain appeal, but how would I create a vector of sets? I'm worried that such a change would break generic code along the lines of
|
We’re removing the DataVector[1, 2, 3] constructor from DataArrays. — John On Dec 1, 2013, at 11:56 AM, Stefan Karpinski [email protected] wrote:
|
If generators (#4470) were implemented, |
change Set, IntSet, and PriorityQueue constructors to accept a single iterable add an ObjectIdDict constructor accepting an iterable now you can do this: ``` julia> pairs = [(1,2), (3,4)]; julia> ObjectIdDict(pairs) {1=>2,3=>4} julia> Dict(pairs) [3=>4,1=>2] julia> Collections.PriorityQueue(pairs) [3=>4,1=>2] julia> Set(pairs) Set{(Int64,Int64)}([(1,2),(3,4)]) ```
#4871 suggests constructing dicts from a single iterable argument generating tuples. We should consider doing the same for sets.
While the syntax
Set(1,2,3)
is nice, it turns ugly when you need to convert a collection to a set, which requiresSet(c...)
. We should avoid expanding an entire collection into an argument list just to pass its elements to a function that wants a collection anyway.This also fits the planned construct/coerce/convert scheme, since
coerce(Set, array)
is more natural thancoerce(Set, 1, 2, 3, ...)
.The text was updated successfully, but these errors were encountered: