Skip to content

Commit 992facd

Browse files
author
Andy Ferris
committed
Added docstrings and tests for compositions
1 parent dc8e1b5 commit 992facd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

base/operators.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,25 @@ eltype(x) = eltype(typeof(x))
332332

333333
|>(x, f) = f(x)
334334

335+
"""
336+
∘(f, g)
337+
f ∘ g
338+
339+
Creates a composition of two functions (or functor objects), such that
340+
`(f ∘ g)(x...) == f(g(x...))`. The `∘` symbol can be accessed at the REPL using
341+
`\\circ`.
342+
343+
By default, an anonymous function `(x...) -> f(g(x...))` is returned, but this may
344+
be specialized to create any functionally-equivalent callable object.
345+
"""
335346
(f, g) = (x...)->f(g(x...))
336347

348+
"""
349+
!(f::Function)
350+
351+
Applies boolean not to the output of `f`, return a new function
352+
`(x...) -> !f(x...)` such that `(!f)(x...) = !(f(x...))`.
353+
"""
337354
!(f::Function) = (x...)->!f(x...)
338355

339356
# array shape rules

test/operators.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ let xs = [[i:i+4;] for i in 1:10]
5555
@test max(xs[1:n]...) == [n:n+4;]
5656
end
5757
end
58+
59+
@test ((x -> x+1) (x _> 2x))(5) == 11
60+
@test (!isless)(1,2) == false

0 commit comments

Comments
 (0)