-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add iteration support for more containers #448
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, I left some inline comments.
function Base.show(io::IO, ::MIME"text/plain", container::StdForwardList) | ||
print(io, "StdForwardList[") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather go for something like:
StdForwardList{<element type>} with X elements:
2
3
1
similar to the way Julia Set
s are printed. The [] syntax risks confusion with arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a forward list, printing the length will require iterating over the entire list, so I have omitted the number of elements and now gone for this:
StdForwardList{Int64}:
2
3
1
src/StdLib/StdList.jl
Outdated
Base.iterate(v::StdList, state::StdListIterator) = (state != iteratorend(v)) ? _list_iteration_tuple(v, iterator_next(state)) : nothing | ||
|
||
function Base.show(io::IO, ::MIME"text/plain", container::StdList) | ||
print(io, "StdList[") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, it is now displayed like this
StdList{Int64} with 3 elements:
2
3
1
src/StdLib/StdDeque.jl
Outdated
Base.pushfirst!(v::StdDeque, x) = push_front!(v, x) | ||
Base.push!(v::StdDeque, x) = isempty(v) ? push_front!(v, x) : push_back!(v, x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The push methods for StdDeque
also need to return the container, as is done for the other types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
https://github.com/PraneethJain/libcxxwrap-julia#iterators
Added iterators for
StdDeque
StdSet
StdUnorderedSet
StdMultiset
StdUnorderedMultiset
StdList
StdForwardList
Base code from #433
Also added pretty printing for
StdList
andStdForwardList
, since they do not have a parent Abstract Type in Julia