Skip to content

Commit

Permalink
deprecate contains(eq, itr, item)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 14, 2017
1 parent ac714a1 commit 2a62586
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 34 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ Deprecated or removed
this is not true. If you are certain you need the old behavior, it is temporarily available
as `Base._isleaftype` ([#17086]).

* `contains(eq, itr, item)` is deprecated in favor of `any` with a predicate.

Command-line option changes
---------------------------

Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,8 @@ import .Iterators.enumerate
return p
end

@deprecate contains(eq::Function, itr, x) any(y->eq(y,x), itr)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
32 changes: 0 additions & 32 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -637,38 +637,6 @@ const ∈ = in
(itr, x)= (x, itr)
(itr, x)=!(itr, x)

"""
contains(fun, itr, x) -> Bool
Returns `true` if there is at least one element `y` in `itr` such that `fun(y,x)` is `true`.
```jldoctest
julia> vec = [10, 100, 200]
3-element Array{Int64,1}:
10
100
200
julia> contains(==, vec, 200)
true
julia> contains(==, vec, 300)
false
julia> contains(>, vec, 100)
true
julia> contains(>, vec, 200)
false
```
"""
function contains(eq::Function, itr, x)
for y in itr
eq(y, x) && return true
end
return false
end


## count

Expand Down
1 change: 0 additions & 1 deletion doc/src/stdlib/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ Base.flipdim
Base.circshift
Base.circshift!
Base.circcopy!
Base.contains(::Function, ::Any, ::Any)
Base.find(::Any)
Base.find(::Function, ::Any)
Base.findn
Expand Down
2 changes: 1 addition & 1 deletion test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ A = reshape(map(UInt8, 1:100), (10,10))
let A = collect(1:10)
@test A 5
@test A 11
@test contains(==,A,6)
@test any(y->y==6,A)
end

# issue #18695
Expand Down

0 comments on commit 2a62586

Please sign in to comment.