Skip to content

Commit

Permalink
Add ASCII alias compose of
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Oct 16, 2019
1 parent c8313c6 commit bc4e8ce
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ New language features
* Function composition now supports multiple functions: `∘(f, g, h) = f ∘ g ∘ h`
and splatting `∘(fs...)` for composing an iterable collection of functions ([#33568]).

* Function composition `` now has an ASCII alias `compose`.

Language changes
----------------

Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ export
# misc
atexit,
atreplinit,
compose,
exit,
ntuple,

Expand Down
7 changes: 6 additions & 1 deletion base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ julia> [1:5;] |> x->x.^2 |> sum |> inv

"""
f ∘ g
compose(f, g)
Compose functions: i.e. `(f ∘ g)(args...)` means `f(g(args...))`. The `∘` symbol can be
entered in the Julia REPL (and most editors, appropriately configured) by typing `\\circ<tab>`.
Expand All @@ -832,7 +833,7 @@ The prefix form supports composition of multiple functions: `∘(f, g, h) = f
and splatting `∘(fs...)` for composing an iterable collection of functions.
!!!compat "Julia 1.4"
Multiple function composition requires at least Julia 1.4.
Multiple function composition and ASCII alias `compose` require at least Julia 1.4.
# Examples
```jldoctest
Expand All @@ -851,10 +852,14 @@ julia> fs = [
julia> ∘(fs...)(3)
3.0
julia> ∘(fs...) === compose(fs...)
true
```
"""
(f, g) = (x...)->f(g(x...))
(f, g, h...) = (f g, h...)
const compose =

"""
!f::Function
Expand Down
1 change: 1 addition & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Base.promote_rule(::Type{T19714}, ::Type{Int}) = T19714
@test (x -> x-2, x -> x-3, x -> x+5)(7) == 7
fs = [x -> x[1:2], uppercase, lowercase]
@test (fs...)("ABC") == "AB"
@test (fs...) === compose(fs...)
end
@testset "function negation" begin
str = randstring(20)
Expand Down

0 comments on commit bc4e8ce

Please sign in to comment.