Skip to content

Commit

Permalink
Backport ComposedFunction (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Sep 25, 2020
1 parent a135ef3 commit e3a642c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
31 changes: 31 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit e3a642c

@martinholters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/21967

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.17.0 -m "<description of version>" e3a642cd92ec0f4b7a55cd45f0400528701487a2
git push origin v3.17.0

Please sign in to comment.