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

add missing eachindex method for indexable collections: SimpleVector, Tuple, and Number #12797

Closed
wants to merge 1 commit into from

Conversation

stevengj
Copy link
Member

This adds a few missing eachindex methods for indexable collections that I noticed in #12788.

I think the principle is that any iterable collection that implements getindex should implement eachindex, to enable the writing of generic code for such indexable collections. That includes SimpleVector (used for low-level stuff like DataType.types), Tuple, and Number (since numbers are indexable collections in Julia, primarily to make it easy to write generic code that works for both vectors and scalars).

@@ -18,6 +18,7 @@ getindex(x::Number, I::Real...) = getindex(x, to_indexes(I...)...)
unsafe_getindex(x::Real, i::Real) = x
first(x::Number) = x
last(x::Number) = x
eachindex(x::Number) = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this definition seems nicely meta: "the list of indices for iterating over a number can be found by iterating over the number 1"

@vtjnash
Copy link
Member

vtjnash commented Aug 25, 2015

it looks like the travis failure was due to some transient network issue (fatal: unable to access 'https://github.com/JuliaLang/Example.jl.git/': Failed connect to github.com:443; Operation timed out)

@stevengj
Copy link
Member Author

restarted travis...

@stevengj
Copy link
Member Author

Seems to be obsolete.

@stevengj stevengj closed this Dec 28, 2016
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.

2 participants