Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invpermute! and a pairs method for replace #445

Merged
merged 3 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ Currently, the `@compat` macro supports the following syntaxes:

* `Some{T}` wraps `T` to signify that a result of `T<:Void` is expected ([#23642]).

* `replace` accepts a pair of pattern and replacement, with the number of replacements as
a keyword argument ([#25165]).

## Renaming


Expand Down Expand Up @@ -266,6 +269,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `unshift!` and `shift!` are now `pushfirst!` and `popfirst!` ([#25100]).

* `ipermute!` is now `invpermute!` ([#25168]).

## New macros

* `@__DIR__` has been added ([#18380])
Expand Down Expand Up @@ -424,3 +429,5 @@ includes this fix. Find the minimum version from there.
[#25100]: https://github.com/JuliaLang/julia/issues/25100
[#25102]: https://github.com/JuliaLang/julia/issues/25102
[#25162]: https://github.com/JuliaLang/julia/issues/25162
[#25165]: https://github.com/JuliaLang/julia/issues/25165
[#25168]: https://github.com/JuliaLang/julia/issues/25168
11 changes: 11 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,17 @@ end
export pushfirst!, popfirst!
end

# 0.7.0-DEV.3173
@static if !isdefined(Base, :invpermute!)
const invpermute! = ipermute!
export invpermute!
end

@static if VERSION < v"0.7.0-DEV.3172"
Base.replace(s::AbstractString, pat_rep::Pair; count::Integer=typemax(Int)) =
replace(s, first(pat_rep), last(pat_rep), count)
end

include("deprecated.jl")

end # module Compat
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,13 @@ let coolvec = [1,2,3]
@test popfirst!(coolvec) == 0
end

# 0.7.0-DEV.3173
@test invpermute!(permute!([1, 2], 2:-1:1), 2:-1:1) == [1, 2]

# 0.7.0-DEV.3172
@test replace("abcb", "b"=>"c") == "accc"
@test replace("abcb", "b"=>"c", count=1) == "accb"

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down