Skip to content

Commit

Permalink
Drop compat code for pairs from #428
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Oct 1, 2019
1 parent 110fb2d commit 4b8e3de
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ Currently, the `@compat` macro supports the following syntaxes:

* `IOContext` accepting key-value `Pair`s ([#23271]).

* `pairs` for iterating over key-value `Pair`s ([#22907]).

* `get` do-block syntax supported when using `ENV` ([#23412]).

* `Some{T}` wraps `T` to signify that a result of `T<:Void` is expected ([#23642]).
Expand Down
17 changes: 0 additions & 17 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ import Base.MathConstants

include("compatmacro.jl")

# 0.7.0-DEV.1660
@static if !isdefined(Base, :pairs)
pairs(collection) = Base.Generator(=>, keys(collection), values(collection))
pairs(a::Associative) = a

const IndexValue = Iterators.IndexValue

pairs(::IndexLinear, A::AbstractArray) = IndexValue(A, linearindices(A))
pairs(::IndexCartesian, A::AbstractArray) = IndexValue(A, CartesianRange(indices(A)))

Base.keys(a::AbstractArray) = CartesianRange(indices(a))
Base.keys(a::AbstractVector) = linearindices(a)
Base.keys(s::IndexStyle, A::AbstractArray, B::AbstractArray...) = eachindex(s, A, B...)

Base.values(itr) = itr
end

# 0.7.0-DEV.1721
@static if !isdefined(Base, :AbstractRange)
const AbstractRange = Range
Expand Down
28 changes: 28 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,31 @@ end
@test partialsort([3,6,30,1,9], 2, by=x->1/x) == 9
@test partialsortperm([3,6,30,1,9], 2, rev=true) == 5
@test partialsortperm([3,6,30,1,9], 2, by=x->1/x) == 5

# PR 22907
using Compat: pairs

# keys, values, pairs
for A in (rand(2), rand(2,3))
local A
for (i, v) in pairs(A)
@test A[i] == v
end
@test collect(values(A)) == collect(A)
end

let A = Dict(:foo=>1, :bar=>3)
for (k, v) in pairs(A)
@test A[k] == v
end
@test sort!(collect(pairs(A))) == sort!(collect(A))
end

let
A14 = [11 13; 12 14]
R = CartesianIndices(Compat.axes(A14))
@test vec([a for (a,b) in pairs(IndexLinear(), A14)]) == [1,2,3,4]
@test vec([a for (a,b) in pairs(IndexCartesian(), A14)]) == vec(collect(R))
@test vec([b for (a,b) in pairs(IndexLinear(), A14)]) == [11,12,13,14]
@test vec([b for (a,b) in pairs(IndexCartesian(), A14)]) == [11,12,13,14]
end
28 changes: 0 additions & 28 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,6 @@ if VERSION < v"0.7.0-DEV.880"
end
end

# PR 22907
using Compat: pairs

# keys, values, pairs
for A in (rand(2), rand(2,3))
local A
for (i, v) in pairs(A)
@test A[i] == v
end
@test collect(values(A)) == collect(A)
end

let A = Dict(:foo=>1, :bar=>3)
for (k, v) in pairs(A)
@test A[k] == v
end
@test sort!(collect(pairs(A))) == sort!(collect(A))
end

let
A14 = [11 13; 12 14]
R = CartesianIndices(Compat.axes(A14))
@test vec([a for (a,b) in pairs(IndexLinear(), A14)]) == [1,2,3,4]
@test vec([a for (a,b) in pairs(IndexCartesian(), A14)]) == vec(collect(R))
@test vec([b for (a,b) in pairs(IndexLinear(), A14)]) == [11,12,13,14]
@test vec([b for (a,b) in pairs(IndexCartesian(), A14)]) == [11,12,13,14]
end

# 0.7
@test isa(1:2, AbstractRange)

Expand Down

0 comments on commit 4b8e3de

Please sign in to comment.