From 8e198e977db5cadd173d9111da2a1fa1013c898c Mon Sep 17 00:00:00 2001 From: Fengyang Wang Date: Sat, 7 Jan 2017 21:35:17 -0500 Subject: [PATCH] =?UTF-8?q?Backport=20=E2=88=98=20and=20!=20from=20#17155?= =?UTF-8?q?=20(#298)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ src/Compat.jl | 7 +++++++ test/runtests.jl | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 6d3e7bb7e4f96..c0c38be76297e 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,10 @@ Currently, the `@compat` macro supports the following syntaxes: * `transcode` converts between UTF-xx string encodings in Julia 0.5 (as a lightweight alternative to the LegacyStrings package), [#17323](https://github.com/JuliaLang/julia/pull/17323). +* `∘` (typically used infix as `f ∘ g`) for function composition can be used in 0.5 and earlier. [#17155](https://github.com/JuliaLang/julia/pull/17155) + +* The method of `!` to negate functions (typically used as a unary operator, as in `!isinteger`) can be used in 0.5 and earlier. [#17155](https://github.com/JuliaLang/julia/pull/17155) + ## Renamed functions * `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively. diff --git a/src/Compat.jl b/src/Compat.jl index c570bd6c56aac..8cb03ba9974e7 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1739,4 +1739,11 @@ if VERSION < v"0.5.0-dev+5380" end end +# julia #17155 function composition and negation +if VERSION < v"0.6.0-dev.1883" + export ∘ + ∘(f, g) = (x...)->f(g(x...)) + @compat Base.:!(f::Function) = (x...)->!f(x...) +end + end # module diff --git a/test/runtests.jl b/test/runtests.jl index 5ef50170f6c25..2cebbf66add14 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1552,3 +1552,10 @@ let s = "Koala test: 🐨" @test transcode(T, s) == transcode(T, s.data) == transcode(T, transcode(T, s)) end end + +# julia#17155, tests from Base Julia +@test (uppercase∘hex)(239487) == "3A77F" +let str = randstring(20) + @test filter(!isupper, str) == replace(str, r"[A-Z]", "") + @test filter(!islower, str) == replace(str, r"[a-z]", "") +end