From 769562bd3a0407101eb7e7e8d9466594d4308dce Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Thu, 5 Jul 2018 17:36:52 +0200 Subject: [PATCH] delete replace[!](pred, A, new) --- base/set.jl | 43 ------------------------------------------- test/sets.jl | 10 +--------- 2 files changed, 1 insertion(+), 52 deletions(-) diff --git a/base/set.jl b/base/set.jl index d7641cd83a279..a3e9954d21477 100644 --- a/base/set.jl +++ b/base/set.jl @@ -362,27 +362,6 @@ function replace_pairs!(res, A, count::Int, old_new::Tuple{Vararg{Pair}}) _replace!(new, res, A, count) end -""" - replace!(pred::Function, A, new; [count::Integer]) - -Replace all occurrences `x` in collection `A` for which `pred(x)` is true -by `new`. - -# Examples -```jldoctest -julia> A = [1, 2, 3, 1]; - -julia> replace!(isodd, A, 0, count=2) -4-element Array{Int64,1}: - 0 - 2 - 0 - 1 -``` -""" -replace!(pred::Callable, A, new; count::Integer=typemax(Int)) = - replace!(x -> ifelse(pred(x), new, x), A, count=check_count(count)) - """ replace!(new::Function, A; [count::Integer]) @@ -473,28 +452,6 @@ end subtract_singletontype(::Type{T}, x::Pair{K}, y::Pair...) where {T, K} = subtract_singletontype(subtract_singletontype(T, y...), x) -""" - replace(pred::Function, A, new; [count::Integer]) - -Return a copy of collection `A` where all occurrences `x` for which -`pred(x)` is true are replaced by `new`. -If `count` is specified, then replace at most `count` occurrences in total. - -# Examples -```jldoctest -julia> replace(isodd, [1, 2, 3, 1], 0, count=2) -4-element Array{Int64,1}: - 0 - 2 - 0 - 1 -``` -""" -function replace(pred::Callable, A, new; count::Integer=typemax(Int)) - T = promote_type(eltype(A), typeof(new)) - _replace!(x -> ifelse(pred(x), new, x), _similar_or_copy(A, T), A, check_count(count)) -end - """ replace(new::Function, A; [count::Integer]) diff --git a/test/sets.jl b/test/sets.jl index 3e5e350e67c17..ea523d43afb72 100644 --- a/test/sets.jl +++ b/test/sets.jl @@ -518,16 +518,12 @@ end @test replace!(x->2x, a, count=0x2) == [4, 8, 3, 2] d = Dict(1=>2, 3=>4) - @test replace(x->x.first > 2, d, 0=>0) == Dict(1=>2, 0=>0) @test replace!(x -> x.first > 2 ? x.first=>2*x.second : x, d) === d @test d == Dict(1=>2, 3=>8) @test replace(d, (3=>8)=>(0=>0)) == Dict(1=>2, 0=>0) @test replace!(d, (3=>8)=>(2=>2)) === d @test d == Dict(1=>2, 2=>2) - for count = (1, 0x1, big(1)) - @test replace(x->x.second == 2, d, 0=>0, count=count) in [Dict(1=>2, 0=>0), - Dict(2=>2, 0=>0)] - end + s = Set([1, 2, 3]) @test replace(x -> x > 1 ? 2x : x, s) == Set([1, 4, 6]) for count = (1, 0x1, big(1)) @@ -553,13 +549,9 @@ end # test eltype promotion x = @inferred replace([1, 2], 2=>2.5) @test x == [1, 2.5] && x isa Vector{Float64} - x = @inferred replace(x -> x > 1, [1, 2], 2.5) - @test x == [1, 2.5] && x isa Vector{Float64} x = @inferred replace([1, 2], 2=>missing) @test isequal(x, [1, missing]) && x isa Vector{Union{Int, Missing}} - x = @inferred replace(x -> x > 1, [1, 2], missing) - @test isequal(x, [1, missing]) && x isa Vector{Union{Int, Missing}} @test_broken @inferred replace([1, missing], missing=>2) x = replace([1, missing], missing=>2)