Skip to content

Commit

Permalink
Merge branch 'master' into fw/stdlib2
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb authored Oct 6, 2017
2 parents 1c4cd10 + 3dbca5d commit 91485f7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ Currently, the `@compat` macro supports the following syntaxes:
`cov(::AbstractVector; corrected=)` and `cov(::AbstractVector, ::AbstractVector; corrected=)`
are only available on 0.6. ([#21709])

* `equalto` constructs an `EqualTo` object that can be used as a predicate ([#23812]).

## Renaming


Expand Down Expand Up @@ -337,4 +339,5 @@ includes this fix. Find the minimum version from there.
[#23427]: https://github.com/JuliaLang/julia/issues/23427
[#23570]: https://github.com/JuliaLang/julia/issues/23570
[#23666]: https://github.com/JuliaLang/julia/issues/23666
[#23812]: https://github.com/JuliaLang/julia/issues/23812
[#23931]: https://github.com/JuliaLang/julia/issues/23931
22 changes: 22 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,28 @@ else
import Test, SharedArrays, Mmap, DelimitedFiles
end

# 0.7.0-DEV.1993
@static if !isdefined(Base, :EqualTo)
if VERSION >= v"0.6.0"
include_string(@__MODULE__, """
struct EqualTo{T} <: Function
x::T
EqualTo(x::T) where {T} = new{T}(x)
end
""")
else
include_string(@__MODULE__, """
immutable EqualTo{T} <: Function
x::T
end
""")
end
(f::EqualTo)(y) = isequal(f.x, y)
const equalto = EqualTo
export equalto
end

include("deprecated.jl")

end # module Compat
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,16 @@ module Test23876
@test isdefined(Mmap, :mmap)
end

let a = [0,1,2,3,0,1,2,3]
@test findfirst(equalto(3), [1,2,4,1,2,3,4]) == 6
@test findfirst(!equalto(1), [1,2,4,1,2,3,4]) == 2
@test findnext(equalto(1), a, 4) == 6
@test findnext(equalto(5), a, 4) == 0
@test findlast(equalto(3), [1,2,4,1,2,3,4]) == 6
@test findprev(equalto(1), a, 4) == 2
@test findprev(equalto(1), a, 8) == 6
end

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down

0 comments on commit 91485f7

Please sign in to comment.