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

make collection constructors more uniform #5897

Merged
merged 5 commits into from Feb 22, 2014
Merged

Conversation

JeffBezanson
Copy link
Sponsor Member

fixes #4996 and #4871

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)])

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)])
```
@JeffBezanson
Copy link
Sponsor Member Author

Come to think of it, it wouldn't be so bad to add a Collection type above AbstractArray, Associative, Set, String, etc. The main problems would be that (1) we can't capture everything that is iterable this way, (2) it's not clear whether some types (like String) really are primarily collections.

@kmsquire
Copy link
Member

+1 for this PR.

I've pointed it out before, but I think the Scala collections hierarchy (or the immutable hierarchy) are well thought out and could provide a basis for collections in Julia.

In particular: Iterable and Sequence abstract types would be useful abstract types to have.

The lack of multiple inheritance in Julia does limit this somewhat (in Scala, these are traits, and classes can have multiple traits).

(This paper describes the meaning of Traversable, Iterable, and Seq in more detail, summarized here)

@stevengj
Copy link
Member

It will be especially nice in conjunction with #4470, as this will give us comprehension-like syntax for all these collections.

@StefanKarpinski
Copy link
Sponsor Member

Yes, very true. That will be a very nice interface.

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

Successfully merging this pull request may close these issues.

change set constructor to accept iterables?
4 participants