Julia: Piping operator |> with multiple arguments

I am trying to pass multiple arguments to the built-in pipeline operator in Julia |>

.

I would like something like this:

join([randstring() for i in 1:100], " ")

      

However, using the pipeline operator, I get the error instead:

[randstring() for i in 1:100] |> join(" ")

      

I'm pretty sure this is a multiple dispatch feature with a connection, having its own method with delim

in the method join(strings, delim, [last])

that is defined as delim=""

when skipped.

Am I getting it right? Is there work around?

For what is worth most of my pipeline applications ends up taking more than one argument. For example:

[randstring() for i in 1:100] |> join(" ") |> replace("|", " ")

      

+3


source to share


1 answer


The pipeline operator does nothing magical. It just takes the values ​​on the left and applies them to the functions on the right. As you've found, join(" ")

doesn't return a function. In general, partial function applications in Julia do not return functions - this will mean something else (via multiple dispatch) or it will be a bug.

There are several options that allow you to support this:



  • Explicitly creating anonymous functions:

    [randstring() for i in 1:100] |> x->join(x, " ") |> x->replace(x, "|", " ")
    
          

  • Use macros to enable the special magic you are looking for. There are several packages that support this.

+4


source







All Articles