Skip to content

Commit cebd0fe

Browse files
committed
delete replace[!](pred, A, new)
1 parent 31bf0b8 commit cebd0fe

File tree

3 files changed

+1
-53
lines changed

3 files changed

+1
-53
lines changed

base/set.jl

-43
Original file line numberDiff line numberDiff line change
@@ -362,27 +362,6 @@ function replace_pairs!(res, A, count::Int, old_new::Tuple{Vararg{Pair}})
362362
_replace!(new, res, A, count)
363363
end
364364

365-
"""
366-
replace!(pred::Function, A, new; [count::Integer])
367-
368-
Replace all occurrences `x` in collection `A` for which `pred(x)` is true
369-
by `new`.
370-
371-
# Examples
372-
```jldoctest
373-
julia> A = [1, 2, 3, 1];
374-
375-
julia> replace!(isodd, A, 0, count=2)
376-
4-element Array{Int64,1}:
377-
0
378-
2
379-
0
380-
1
381-
```
382-
"""
383-
replace!(pred::Callable, A, new; count::Integer=typemax(Int)) =
384-
replace!(x -> ifelse(pred(x), new, x), A, count=check_count(count))
385-
386365
"""
387366
replace!(new::Function, A; [count::Integer])
388367
@@ -473,28 +452,6 @@ end
473452
subtract_singletontype(::Type{T}, x::Pair{K}, y::Pair...) where {T, K} =
474453
subtract_singletontype(subtract_singletontype(T, y...), x)
475454

476-
"""
477-
replace(pred::Function, A, new; [count::Integer])
478-
479-
Return a copy of collection `A` where all occurrences `x` for which
480-
`pred(x)` is true are replaced by `new`.
481-
If `count` is specified, then replace at most `count` occurrences in total.
482-
483-
# Examples
484-
```jldoctest
485-
julia> replace(isodd, [1, 2, 3, 1], 0, count=2)
486-
4-element Array{Int64,1}:
487-
0
488-
2
489-
0
490-
1
491-
```
492-
"""
493-
function replace(pred::Callable, A, new; count::Integer=typemax(Int))
494-
T = promote_type(eltype(A), typeof(new))
495-
_replace!(x -> ifelse(pred(x), new, x), _similar_or_copy(A, T), A, check_count(count))
496-
end
497-
498455
"""
499456
replace(new::Function, A; [count::Integer])
500457

doc/src/base/collections.md

-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ Base.collect(::Type, ::Any)
134134
Base.filter
135135
Base.filter!
136136
Base.replace(::Any, ::Pair...)
137-
Base.replace(::Base.Callable, ::Any, ::Any)
138137
Base.replace(::Base.Callable, ::Any)
139138
Base.replace!
140139
```

test/sets.jl

+1-9
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,12 @@ end
518518
@test replace!(x->2x, a, count=0x2) == [4, 8, 3, 2]
519519

520520
d = Dict(1=>2, 3=>4)
521-
@test replace(x->x.first > 2, d, 0=>0) == Dict(1=>2, 0=>0)
522521
@test replace!(x -> x.first > 2 ? x.first=>2*x.second : x, d) === d
523522
@test d == Dict(1=>2, 3=>8)
524523
@test replace(d, (3=>8)=>(0=>0)) == Dict(1=>2, 0=>0)
525524
@test replace!(d, (3=>8)=>(2=>2)) === d
526525
@test d == Dict(1=>2, 2=>2)
527-
for count = (1, 0x1, big(1))
528-
@test replace(x->x.second == 2, d, 0=>0, count=count) in [Dict(1=>2, 0=>0),
529-
Dict(2=>2, 0=>0)]
530-
end
526+
531527
s = Set([1, 2, 3])
532528
@test replace(x -> x > 1 ? 2x : x, s) == Set([1, 4, 6])
533529
for count = (1, 0x1, big(1))
@@ -553,13 +549,9 @@ end
553549
# test eltype promotion
554550
x = @inferred replace([1, 2], 2=>2.5)
555551
@test x == [1, 2.5] && x isa Vector{Float64}
556-
x = @inferred replace(x -> x > 1, [1, 2], 2.5)
557-
@test x == [1, 2.5] && x isa Vector{Float64}
558552

559553
x = @inferred replace([1, 2], 2=>missing)
560554
@test isequal(x, [1, missing]) && x isa Vector{Union{Int, Missing}}
561-
x = @inferred replace(x -> x > 1, [1, 2], missing)
562-
@test isequal(x, [1, missing]) && x isa Vector{Union{Int, Missing}}
563555

564556
@test_broken @inferred replace([1, missing], missing=>2)
565557
x = replace([1, missing], missing=>2)

0 commit comments

Comments
 (0)