From 849dbc78380c14a650288e332084135b565541bd Mon Sep 17 00:00:00 2001 From: mschauer Date: Sun, 20 Sep 2015 17:52:16 +0200 Subject: [PATCH] Make |> wellbehaved with regard to splatting --- base/docs/helpdb.jl | 3 ++- base/operators.jl | 2 ++ test/operators.jl | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/docs/helpdb.jl b/base/docs/helpdb.jl index 48e030f43b403..46b8106b54ff2 100644 --- a/base/docs/helpdb.jl +++ b/base/docs/helpdb.jl @@ -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 diff --git a/base/operators.jl b/base/operators.jl index ad7e66213b9b3..b2639371bc011 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -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 diff --git a/test/operators.jl b/test/operators.jl index 6106afa1bd330..7b84437c108ce 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -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