Skip to content

Commit

Permalink
Function composition for multiple functions (JuliaLang/julia#33568)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Oct 16, 2019
1 parent 4fa5519 commit ee09e5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Currently, the `@compat` macro supports the following syntaxes:

## Other changes

* Function composition now supports multiple functions: `∘(f, g, h) = f ∘ g ∘ h`
and splatting `∘(fs...)` for composing an iterable collection of functions ([#33568]).

## New types

## Developer tips
Expand Down Expand Up @@ -127,3 +130,4 @@ includes this fix. Find the minimum version from there.
[#29749]: https://github.com/JuliaLang/julia/issues/29749
[#32628]: https://github.com/JuliaLang/julia/issues/32628
[#33129]: https://github.com/JuliaLang/julia/issues/33129
[#33568]: https://github.com/JuliaLang/julia/pull/33568
5 changes: 5 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ if VERSION < v"1.3.0-alpha.8"
Base.mod(i::Integer, r::AbstractUnitRange{<:Integer}) = mod(i-first(r), length(r)) + first(r)
end

# https://github.com/JuliaLang/julia/pull/33568
if VERSION < v"1.4.0-DEV.329"
Base.:(f, g, h...) = (f g, h...)
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 @@ -90,4 +90,11 @@ end
@test_throws DivideError mod(3, 1:0)
end

# https://github.com/JuliaLang/julia/pull/33568
@testset "function composition" begin
@test (x -> x-2, x -> x-3, x -> x+5)(7) == 7
fs = [x -> x[1:2], uppercase, lowercase]
@test (fs...)("ABC") == "AB"
end

nothing

0 comments on commit ee09e5d

Please sign in to comment.