Skip to content

Commit 1855583

Browse files
udohjeremiahmcabbottLilithHafner
authored
complete info on the |> operator (#46890)
Co-authored-by: Michael Abbott <[email protected]> Co-authored-by: Lilith Orion Hafner <[email protected]>
1 parent 1c172e1 commit 1855583

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

base/operators.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,13 +887,21 @@ widen(x::Type{T}) where {T} = throw(MethodError(widen, (T,)))
887887
"""
888888
|>(x, f)
889889
890-
Applies a function to the preceding argument. This allows for easy function chaining.
891-
When used with anonymous functions, parentheses are typically required around the definition to get the intended chain.
890+
Infix operator which applies function `f` to the argument `x`.
891+
This allows `f(g(x))` to be written `x |> g |> f`.
892+
When used with anonymous functions, parentheses are typically required around
893+
the definition to get the intended chain.
892894
893895
# Examples
894896
```jldoctest
895-
julia> [1:5;] .|> (x -> x^2) |> sum |> inv
896-
0.01818181818181818
897+
julia> 4 |> inv
898+
0.25
899+
900+
julia> [2, 3, 5] |> sum |> inv
901+
0.1
902+
903+
julia> [0 1; 2 3] .|> (x -> x^2) |> sum
904+
14
897905
```
898906
"""
899907
|>(x, f) = f(x)

0 commit comments

Comments
 (0)