Skip to content

Commit

Permalink
Merge pull request #12335 from JuliaLang/jh/last-pair
Browse files Browse the repository at this point in the history
Add endof for Pair
  • Loading branch information
mlubin committed Jul 28, 2015
2 parents 9738275 + 71ee608 commit 53aabc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/operators.jl
Expand Up @@ -441,6 +441,8 @@ getindex(p::Pair,i::Int) = getfield(p,i)
getindex(p::Pair,i::Real) = getfield(p, convert(Int, i))
reverse(p::Pair) = Pair(p.second, p.first)

endof(p::Pair) = 2

# some operators not defined yet
global //, >:, <|, hcat, hvcat, , ×, , , , , , , , , , ,

Expand Down
8 changes: 8 additions & 0 deletions test/operators.jl
Expand Up @@ -20,3 +20,11 @@ B = [true true false]

@test reverse(Pair(1,2)) == Pair(2,1)
@test reverse(Pair("13","24")) == Pair("24","13")

p = 1=>:foo
@test first(p) == 1
@test last(p) == :foo
@test first(reverse(p)) == :foo
@test last(reverse(p)) == 1
@test endof(p) == 2
@test p[endof(p)] == p[end] == p[2] == :foo

0 comments on commit 53aabc0

Please sign in to comment.