From ac4ec7b354901835fa928a2d7ead4720fc62e198 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 14 Sep 2017 16:02:27 -0400 Subject: [PATCH] deprecate `contains(eq, itr, item)` --- NEWS.md | 2 ++ base/deprecated.jl | 2 ++ base/reduce.jl | 32 -------------------------------- doc/src/stdlib/arrays.md | 1 - test/reduce.jl | 2 +- 5 files changed, 5 insertions(+), 34 deletions(-) diff --git a/NEWS.md b/NEWS.md index 751386438661e..f4069ec5206f4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ([#23716]). + Command-line option changes --------------------------- diff --git a/base/deprecated.jl b/base/deprecated.jl index d09166cad969f..c1fd510d766ec 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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 diff --git a/base/reduce.jl b/base/reduce.jl index 6b0415fbe266d..418e686307206 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -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 diff --git a/doc/src/stdlib/arrays.md b/doc/src/stdlib/arrays.md index 7c46de37df2b4..1f6a8d0c4f7e4 100644 --- a/doc/src/stdlib/arrays.md +++ b/doc/src/stdlib/arrays.md @@ -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 diff --git a/test/reduce.jl b/test/reduce.jl index 9605b9b0a0707..bbcf4b1b9400b 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -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