Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ASCII alias compose of #33573

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ New language features

* `import` now allows quoted symbols, e.g. `import Base.:+` ([#33158]).

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

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

Expand All @@ -36,6 +33,9 @@ New library functions
* `readdir` output is now guaranteed to be sorted. The `sort` keyword allows opting out of sorting to get names in OS-native order ([#33542]).
* The new `only(x)` function returns the one-and-only element of a collection `x`, and throws an `ArgumentError` if `x` contains zero or multiple elements. ([#33129])
* `takewhile` and `dropwhile` have been added to the Iterators submodule ([#33437]).
* 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` ([#33573]).


Standard library 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> compose(fs...)(3)
3.0
```
"""
∘(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