Skip to content

Commit ee09e5d

Browse files
committed
Function composition for multiple functions (JuliaLang/julia#33568)
1 parent 4fa5519 commit ee09e5d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Currently, the `@compat` macro supports the following syntaxes:
6969

7070
## Other changes
7171

72+
* Function composition now supports multiple functions: `∘(f, g, h) = f ∘ g ∘ h`
73+
and splatting `∘(fs...)` for composing an iterable collection of functions ([#33568]).
74+
7275
## New types
7376

7477
## Developer tips
@@ -127,3 +130,4 @@ includes this fix. Find the minimum version from there.
127130
[#29749]: https://github.com/JuliaLang/julia/issues/29749
128131
[#32628]: https://github.com/JuliaLang/julia/issues/32628
129132
[#33129]: https://github.com/JuliaLang/julia/issues/33129
133+
[#33568]: https://github.com/JuliaLang/julia/pull/33568

src/Compat.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ if VERSION < v"1.3.0-alpha.8"
8888
Base.mod(i::Integer, r::AbstractUnitRange{<:Integer}) = mod(i-first(r), length(r)) + first(r)
8989
end
9090

91+
# https://github.com/JuliaLang/julia/pull/33568
92+
if VERSION < v"1.4.0-DEV.329"
93+
Base.:(f, g, h...) = (f g, h...)
94+
end
95+
9196
include("deprecated.jl")
9297

9398
end # module Compat

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,11 @@ end
9090
@test_throws DivideError mod(3, 1:0)
9191
end
9292

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

0 commit comments

Comments
 (0)