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

Make |> wellbehaved with regard to splatting #13240

Closed
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1538,8 +1538,9 @@ cconvert

doc"""
|>(x, f)
|>(x, y, ..., f)

Applies a function to the preceding argument. This allows for easy function chaining.
Applies a function to the preceding argument(s). This allows for easy function chaining.

```jldoctest
julia> [1:5;] |> x->x.^2 |> sum |> inv
Expand Down
2 changes: 2 additions & 0 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ copy(x::Union{Symbol,Number,AbstractString,Function,Tuple,LambdaStaticData,

# function pipelining
|>(x, f) = f(x)
|>(x, y, f) = f(x, y)
|>(args...) = args[end](args[1:end-1]...)

# array shape rules

Expand Down
2 changes: 2 additions & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ p = 1=>:foo
@test 1 .< 2
@test 1 .<= 2

@test minmax(2,1)... |> tuple == (1,2) # test splicing in combination with pipelining

# issue #13144: max() with 4 or more array arguments
let xs = [[i:i+4;] for i in 1:10]
for n in 2:10
Expand Down