diff --git a/NEWS.md b/NEWS.md index 684a5b28cef24..f09d36e70d6d3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -563,7 +563,7 @@ Library improvements * `diagm` now accepts several diagonal index/vector `Pair`s ([#24047]). * `isequal`, `==`, and `in` have one argument "curried" forms. For example `isequal(x)` - returns a function that compares its argument to `x` using `isequal` ([#23812]). + returns a function that compares its argument to `x` using `isequal` ([#26436]). * `reinterpret` now works on any AbstractArray using the new `ReinterpretArray` type. This supersedes the old behavior of reinterpret on Arrays. As a result, reinterpreting @@ -1287,7 +1287,6 @@ Command-line option changes [#23750]: https://github.com/JuliaLang/julia/issues/23750 [#23757]: https://github.com/JuliaLang/julia/issues/23757 [#23805]: https://github.com/JuliaLang/julia/issues/23805 -[#23812]: https://github.com/JuliaLang/julia/issues/23812 [#23816]: https://github.com/JuliaLang/julia/issues/23816 [#23885]: https://github.com/JuliaLang/julia/issues/23885 [#23902]: https://github.com/JuliaLang/julia/issues/23902 @@ -1414,4 +1413,5 @@ Command-line option changes [#26262]: https://github.com/JuliaLang/julia/issues/26262 [#26284]: https://github.com/JuliaLang/julia/issues/26284 [#26286]: https://github.com/JuliaLang/julia/issues/26286 -[#26442]: https://github.com/JuliaLang/julia/issues/26442 \ No newline at end of file +[#26436]: https://github.com/JuliaLang/julia/issues/26436 +[#26442]: https://github.com/JuliaLang/julia/issues/26442 diff --git a/base/array.jl b/base/array.jl index b48cb9cc649eb..0f3297f0143e6 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1984,7 +1984,7 @@ end findall(x::Bool) = x ? [1] : Vector{Int}() findall(testf::Function, x::Number) = testf(x) ? [1] : Vector{Int}() -findall(p::OccursIn, x::Number) = x in p.x ? [1] : Vector{Int}() +findall(p::Fix2{typeof(in)}, x::Number) = x in p.x ? [1] : Vector{Int}() """ findmax(itr) -> (x, index) @@ -2208,7 +2208,7 @@ function _sortedfindin(v, w) return out end -function findall(pred::OccursIn{<:Union{Array{<:Real},Real}}, x::Array{<:Real}) +function findall(pred::Fix2{typeof(in),<:Union{Array{<:Real},Real}}, x::Array{<:Real}) if issorted(x, Sort.Forward) && issorted(pred.x, Sort.Forward) return _sortedfindin(x, pred.x) else @@ -2217,7 +2217,7 @@ function findall(pred::OccursIn{<:Union{Array{<:Real},Real}}, x::Array{<:Real}) end # issorted fails for some element types so the method above has to be restricted # to element with isless/< defined. -findall(pred::OccursIn, x::Union{AbstractArray, Tuple}) = _findin(x, pred.x) +findall(pred::Fix2{typeof(in)}, x::Union{AbstractArray, Tuple}) = _findin(x, pred.x) # Copying subregions function indcopy(sz::Dims, I::Vector) diff --git a/base/bitarray.jl b/base/bitarray.jl index e078f7330c68c..9e5b455475f27 100644 --- a/base/bitarray.jl +++ b/base/bitarray.jl @@ -1509,7 +1509,8 @@ end findfirstnot(B::BitArray) = findnextnot(B,1) # returns the index of the first matching element -function findnext(pred::EqualTo, B::BitArray, start::Integer) +function findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool}, + B::BitArray, start::Integer) v = pred.x v == false && return findnextnot(B, start) v == true && return findnext(B, start) @@ -1581,7 +1582,8 @@ end findlastnot(B::BitArray) = findprevnot(B, length(B)) # returns the index of the previous matching element -function findprev(pred::EqualTo, B::BitArray, start::Integer) +function findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},Bool}, + B::BitArray, start::Integer) v = pred.x v == false && return findprevnot(B, start) v == true && return findprev(B, start) diff --git a/base/deprecated.jl b/base/deprecated.jl index 2a87ebed73f2f..fe310cbe6b542 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1510,6 +1510,12 @@ end # Issue #26248 @deprecate conj(x) x +# PR #26436 +@deprecate equalto(x) isequal(x) +@deprecate(occursin(x), in(x)) +@deprecate_binding EqualTo Base.Fix2{typeof(isequal)} false +@deprecate_binding OccursIn Base.Fix2{typeof(in)} false + # Remove ambiguous CartesianIndices and LinearIndices constructors that are ambiguous between an axis and an array (#26448) @eval IteratorsMD @deprecate CartesianIndices(inds::Vararg{AbstractUnitRange{Int},N}) where {N} CartesianIndices(inds) @eval IteratorsMD @deprecate CartesianIndices(inds::Vararg{AbstractUnitRange{<:Integer},N}) where {N} CartesianIndices(inds) diff --git a/base/iobuffer.jl b/base/iobuffer.jl index 92ec5f386fa3c..e76898fdc1e99 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -435,18 +435,18 @@ read(io::GenericIOBuffer) = read!(io,StringVector(bytesavailable(io))) readavailable(io::GenericIOBuffer) = read(io) read(io::GenericIOBuffer, nb::Integer) = read!(io,StringVector(min(nb, bytesavailable(io)))) -function findfirst(delim::EqualTo{UInt8}, buf::IOBuffer) +function findfirst(delim::Fix2{<:Union{typeof(isequal),typeof(==)},UInt8}, buf::IOBuffer) p = pointer(buf.data, buf.ptr) q = GC.@preserve buf ccall(:memchr,Ptr{UInt8},(Ptr{UInt8},Int32,Csize_t),p,delim.x,bytesavailable(buf)) q == C_NULL && return nothing return Int(q-p+1) end -function findfirst(delim::EqualTo{UInt8}, buf::GenericIOBuffer) +function findfirst(isdelim::Fix2{<:Union{typeof(isequal),typeof(==)},UInt8}, buf::GenericIOBuffer) data = buf.data - for i = buf.ptr : buf.size + for i = buf.ptr:buf.size @inbounds b = data[i] - if b == delim.x + if isdelim(b) return i - buf.ptr + 1 end end diff --git a/base/operators.jl b/base/operators.jl index b61e265068666..c2511bc693fa9 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -837,8 +837,6 @@ used to implement specialized methods. """ isequal(x) = Fix2(isequal, x) -const EqualTo = Fix2{typeof(isequal)} - """ ==(x) @@ -861,8 +859,6 @@ used to implement specialized methods. """ in(x) = Fix2(in, x) -const OccursIn = Fix2{typeof(in)} - """ splat(f) diff --git a/base/precompile.jl b/base/precompile.jl index c688643cb73f6..a5ba000a638bc 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -291,7 +291,8 @@ precompile(Tuple{typeof(Base.find_env), Array{Base.AbstractEnv, 1}}) precompile(Tuple{typeof(Base.find_env), Base.CurrentEnv}) precompile(Tuple{typeof(Base.find_env), Base.NamedEnv}) precompile(Tuple{typeof(Base.find_env), typeof(Pkg.dir)}) -precompile(Tuple{typeof(Base.findfirst), Base.EqualTo{UInt8}, Base.GenericIOBuffer{Array{UInt8, 1}}}) +precompile(Tuple{typeof(Base.findfirst), Base.Fix2{typeof(isequal),UInt8}, Base.GenericIOBuffer{Array{UInt8, 1}}}) +precompile(Tuple{typeof(Base.findfirst), Base.Fix2{typeof(==),UInt8}, Base.GenericIOBuffer{Array{UInt8, 1}}}) precompile(Tuple{typeof(Base.first), Base.OneTo{Int64}}) precompile(Tuple{typeof(Base.firstindex), String}) precompile(Tuple{typeof(Base.flush), Base.IOStream}) diff --git a/base/strings/search.jl b/base/strings/search.jl index cbe6d78e1f352..f9c155d2a944b 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -2,7 +2,8 @@ nothing_sentinel(i) = i == 0 ? nothing : i -function findnext(pred::EqualTo{<:AbstractChar}, s::String, i::Integer) +function findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:AbstractChar}, + s::String, i::Integer) if i < 1 || i > sizeof(s) i == sizeof(s) + 1 && return nothing throw(BoundsError(s, i)) @@ -13,14 +14,15 @@ function findnext(pred::EqualTo{<:AbstractChar}, s::String, i::Integer) while true i = _search(s, first_utf8_byte(c), i) i == 0 && return nothing - s[i] == c && return i + pred(s[i]) && return i i = nextind(s, i) end end -findfirst(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray) = nothing_sentinel(_search(a, pred.x)) +findfirst(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray) = + nothing_sentinel(_search(a, pred.x)) -findnext(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) = +findnext(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) = nothing_sentinel(_search(a, pred.x, i)) function _search(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer = 1) @@ -44,21 +46,23 @@ function _search(a::ByteArray, b::AbstractChar, i::Integer = 1) end end -function findprev(pred::EqualTo{<:AbstractChar}, s::String, i::Integer) +function findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:AbstractChar}, + s::String, i::Integer) c = pred.x c ≤ '\x7f' && return nothing_sentinel(_rsearch(s, c % UInt8, i)) b = first_utf8_byte(c) while true i = _rsearch(s, b, i) i == 0 && return nothing - s[i] == c && return i + pred(s[i]) && return i i = prevind(s, i) end end -findlast(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray) = nothing_sentinel(_rsearch(a, pred.x)) +findlast(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray) = + nothing_sentinel(_rsearch(a, pred.x)) -findprev(pred::EqualTo{<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) = +findprev(pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:Union{Int8,UInt8}}, a::ByteArray, i::Integer) = nothing_sentinel(_rsearch(a, pred.x, i)) function _rsearch(a::Union{String,ByteArray}, b::Union{Int8,UInt8}, i::Integer = sizeof(a)) diff --git a/stdlib/Pkg3/src/precompile.jl b/stdlib/Pkg3/src/precompile.jl index 3913c2fe3104d..f3673f27ac375 100644 --- a/stdlib/Pkg3/src/precompile.jl +++ b/stdlib/Pkg3/src/precompile.jl @@ -258,7 +258,8 @@ precompile(Tuple{typeof(Base.copy), Array{Base.UUID, 1}}) precompile(Tuple{typeof(Base.copyto!), Array{Any, 1}, Tuple{String, Base.VersionNumber, String, String}}) precompile(Tuple{typeof(Base.copyto!), Array{Any, 1}, Tuple{String, Base.VersionNumber}}) precompile(Tuple{typeof(Base.count), Base.BitArray{1}}) -precompile(Tuple{typeof(Base.count), Base.EqualTo{Char}, String}) +precompile(Tuple{typeof(Base.count), Base.Fix2{typeof(isequal),Char}, String}) +precompile(Tuple{typeof(Base.count), Base.Fix2{typeof(==),Char}, String}) precompile(Tuple{typeof(Base.deepcopy), Base.Dict{String, Any}}) precompile(Tuple{typeof(Base.deepcopy_internal), Array{Base.Dict{String, Any}, 1}, Base.IdDict{Any, Any}}) precompile(Tuple{typeof(Base.deepcopy_internal), Base.Dict{Any, Any}, Base.IdDict{Any, Any}}) diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index 1cfafa942f7d7..92edb70aedcff 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -1318,8 +1318,8 @@ function findall(p::Function, S::SparseMatrixCSC) return inds end -findall(p::Base.OccursIn, x::SparseMatrixCSC) = - invoke(findall, Tuple{Base.OccursIn, AbstractArray}, p, x) +findall(p::Base.Fix2{typeof(in)}, x::SparseMatrixCSC) = + invoke(findall, Tuple{Base.Fix2{typeof(in)}, AbstractArray}, p, x) function findnz(S::SparseMatrixCSC{Tv,Ti}) where {Tv,Ti} numnz = nnz(S) diff --git a/stdlib/SparseArrays/src/sparsevector.jl b/stdlib/SparseArrays/src/sparsevector.jl index 4bb0faa7302c9..728fe420a221d 100644 --- a/stdlib/SparseArrays/src/sparsevector.jl +++ b/stdlib/SparseArrays/src/sparsevector.jl @@ -712,8 +712,8 @@ function findall(p::Function, x::SparseVector{<:Any,Ti}) where Ti return I end -findall(p::Base.OccursIn, x::SparseVector{<:Any,Ti}) where {Ti} = - invoke(findall, Tuple{Base.OccursIn, AbstractArray}, p, x) +findall(p::Base.Fix2{typeof(in)}, x::SparseVector{<:Any,Ti}) where {Ti} = + invoke(findall, Tuple{Base.Fix2{typeof(in)}, AbstractArray}, p, x) function findnz(x::SparseVector{Tv,Ti}) where {Tv,Ti} numnz = nnz(x) diff --git a/test/ranges.jl b/test/ranges.jl index f723112b49dfa..176be5412d674 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -249,7 +249,7 @@ end @test length(0.0:-0.5) == 0 @test length(1:2:0) == 0 end - @testset "findall(::OccursIn, ::Array)" begin + @testset "findall(::Base.Fix2{typeof(in)}, ::Array)" begin @test findall(in(3:20), [5.2, 3.3]) == findall(in(Vector(3:20)), [5.2, 3.3]) let span = 5:20,