Skip to content

Commit

Permalink
Add equalto (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored Oct 6, 2017
1 parent 956b34b commit 3dbca5d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,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 @@ -331,3 +333,4 @@ 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
22 changes: 22 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,28 @@ end
export isconcrete
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
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,17 @@ end
# 0.7
@test isconcrete(Int)

# 0.7
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 3dbca5d

Please sign in to comment.