diff --git a/base/operators.jl b/base/operators.jl index c572026fcba76..58f4c9f899481 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -332,8 +332,25 @@ eltype(x) = eltype(typeof(x)) |>(x, f) = f(x) +""" + ∘(f, g) + f ∘ g + +Creates a composition of two functions (or functor objects), such that +`(f ∘ g)(x...) == f(g(x...))`. The `∘` symbol can be accessed at the REPL using +`\\circ`. + +By default, an anonymous function `(x...) -> f(g(x))` is returned, but this may +be specialized to create any functionally-equivalent callable object. +""" ∘(f, g) = (x...)->f(g(x...)) +""" + !(f::Function) + +Applies boolean not to the output of `f`, return a new function +`(x...) -> !f(x...)` such that `(!f)(x...) = !(f(x...))`. +""" !(f::Function) = (x...)->!f(x...) # array shape rules diff --git a/test/operators.jl b/test/operators.jl index 36f80a6033ddf..c3d63b3e25b05 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -55,3 +55,6 @@ let xs = [[i:i+4;] for i in 1:10] @test max(xs[1:n]...) == [n:n+4;] end end + +@test ((x -> x+1) ∘ (x _> 2x))(5) == 11 +@test (!isless)(1,2) == false