diff --git a/Project.toml b/Project.toml index aebaaa283..68a5d3e35 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Compat" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.16.0" +version = "3.17.0" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/README.md b/README.md index 09c032ca6..cf73372a6 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ changes in `julia`. ## Supported features +* The composition operator `∘` now returns a `Compat.ComposedFunction` instead of an anonymous function ([#37517]). (since Compat 3.17) + * New function `addenv` for adding environment mappings into a `Cmd` object, returning the new `Cmd` object ([#37244]). (since Compat 3.16) * `contains(haystack, needle)` and its one argument partially applied form `contains(haystack)` have been added, it acts like `occursin(needle, haystack)` ([#35132]). (since Compat 3.15) @@ -200,3 +202,4 @@ Note that you should specify the correct minimum version for `Compat` in the [#35132]: https://github.com/JuliaLang/julia/pull/35132 [#35052]: https://github.com/JuliaLang/julia/pull/35052 [#37244]: https://github.com/JuliaLang/julia/pull/37244 +[#37517]: https://github.com/JuliaLang/julia/pull/37517 diff --git a/src/Compat.jl b/src/Compat.jl index 6d0afdab8..d7e824b8e 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -607,6 +607,37 @@ if VERSION < v"1.5.0-DEV.438" # 0a43c0f1d21ce9c647c49111d93927369cd20f85 Base.startswith(s) = Base.Fix2(startswith, s) end +# https://github.com/JuliaLang/julia/pull/37517 +if VERSION < v"1.6.0-DEV.1037" + export ComposedFunction + # https://github.com/JuliaLang/julia/pull/35980 + if VERSION < v"1.6.0-DEV.85" + const ComposedFunction = let h = identity ∘ convert + Base.typename(typeof(h)).wrapper + end + @eval ComposedFunction{F,G}(f, g) where {F,G} = + $(Expr(:new, :(ComposedFunction{F,G}), :f, :g)) + ComposedFunction(f, g) = ComposedFunction{Core.Typeof(f),Core.Typeof(g)}(f, g) + else + using Base: ComposedFunction + end + function Base.getproperty(c::ComposedFunction, p::Symbol) + if p === :f + return getfield(c, :f) + elseif p === :g + return getfield(c, :g) + elseif p === :outer + return getfield(c, :f) + elseif p === :inner + return getfield(c, :g) + end + error("type ComposedFunction has no property ", p) + end + Base.propertynames(c::ComposedFunction) = (:f, :g, :outer, :inner) +else + using Base: ComposedFunction +end + # https://github.com/JuliaLang/julia/pull/37244 if VERSION < v"1.6.0-DEV.873" # 18198b1bf85125de6cec266eac404d31ccc2e65c export addenv diff --git a/test/runtests.jl b/test/runtests.jl index 61b381a2d..75735da79 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -556,6 +556,22 @@ end @test endswith("d")("abcd") end +# https://github.com/JuliaLang/julia/pull/37517 +@testset "ComposedFunction" begin + @test sin ∘ cos isa Compat.ComposedFunction + @test sin ∘ cos === Compat.ComposedFunction(sin, cos) + c = sin ∘ cos + @test c.outer === sin + @test c.inner === cos + if VERSION < v"1.6.0-DEV.1037" + @test c.f === sin + @test c.g === cos + @test propertynames(c) == (:f, :g, :outer, :inner) + else + @test propertynames(c) == (:outer, :inner) + end +end + # From spawn.jl shcmd = `sh` havebb = false