Thanks, I like it, nice one liner. 

Definitely useful for quick prototyping in REPL if too slow for production 
code. 

- A

marți, 29 decembrie 2015, 18:28:56 UTC+1, Ismael Venegas Castelló a scris:
>
> My proposal in the PR is:
>
> julia> show_off(x, y) = (@show x y; nothing)
> show_off (generic function with 1 method)
>
> julia> show_off(1, 2)
> x = 1
> y = 2
>
> julia> (1, 2) |> show_off
> ERROR: MethodError: `show_off` has no method matching 
> show_off(::Tuple{Int64,Int
> 64})
> Closest candidates are:
>   show_off(::Any, ::Any)
>  in |> at operators.jl:198
>  in eval at boot.jl:263
>
> julia> Base.|>(xs::Tuple, f) = f(xs...)
> |> (generic function with 7 methods)
>
> julia> (1, 2) |> show_off
> x = 1
> y = 2
>
> Note: splat *...* is slow, type inference is broken don't use this in 
> performance critical code. Since this is I/O it's ok I guess. Since |> may 
> be deprecated, in the future there also may be a package that allows to do 
> this and extend the functionality beyond, for now you have to define that 
> method yourself, if you decide t use it you can put the method definition 
> in you ~/.juliarc.jl configuration file.
>
>
>
> El martes, 29 de diciembre de 2015, 11:02:09 (UTC-6), Adrian Salceanu 
> escribió:
>>
>> I'm a bit puzzled by the behavior of the pipe operator when feeding 
>> values to functions expecting multiple arguments. Basically it doesn't seem 
>> to work at all. Am I missing something? 
>>
>> Ex: 
>>
>> julia> function show_off(x, y)
>>        println(x)
>>        println(y)
>>        end
>> show_off (generic function with 1 method)
>>
>>
>> julia> show_off(1, 2)
>> 1
>> 2
>>
>>
>> julia> 1 |> show_off(2)
>> ERROR: MethodError: `show_off` has no method matching show_off(::Int64)
>> Closest candidates are:
>>   show_off(::Any, ::Any)
>>
>>
>> julia> 1,2 |> show_off
>> ERROR: MethodError: `show_off` has no method matching show_off(::Int64)
>> Closest candidates are:
>>   show_off(::Any, ::Any)
>>  in |> at operators.jl:198
>>
>>
>> julia> (1,2) |> show_off
>> ERROR: MethodError: `show_off` has no method matching show_off(::Tuple{
>> Int64,Int64})
>> Closest candidates are:
>>   show_off(::Any, ::Any)
>>  in |> at operators.jl:198
>>
>>

Reply via email to