title: map, reduce with `|>` in julia
body: <p>In R, with <code>dyplr</code> you have the <code>%&gt;%</code> operator which allows you to pipe the output of a function to a new function, removing the need to store intermediate values. In julia you can achieve something very similar by using the <code>|&gt;</code> operator. </p>
  
  <h3>Example usage</h3>
  
  <pre><code>2 |&gt; log |&gt; sqrt 
  </code></pre>
  
  <p>To me this reads a lot nicer than <code>sqrt(log(2))</code>. Especially when the chain becomes very long. I would like to use this syntax but also for <code>map</code>,<code>reduce</code>-type functions in Julia. </p>
  
  <h3>Setup</h3>
  
  <pre><code>from = "abcdefghijklmnopqrstuvwxyz"
  to   = "cdefghijklmnopqrstuvwxyzab"
  trans = "g fmnc wms bgblr rpylqjyrc gr zw fylb &lt;&gt;"
  d = {from[i] =&gt; to[i] for i = 1:26}
  d[' '] = ' '
  </code></pre>
  
  <h3>What works</h3>
  
  <pre><code>map(x -&gt; d[x], filter(x -&gt; isalpha(x) || isspace(x), trans))
  </code></pre>
  
  <p>This works, but it doesn't read as well as I would like it to. An alternative would be to store intermediate results into variables, but this also seems verbose: </p>
  
  <pre><code>res1 = filter(x -&gt; isalpha(x) || isspace(x), trans)
  map(x -&gt; d[x], res1)
  </code></pre>
  
  <h3>What I would prefer</h3>
  
  <p>The R syntax would be something similar to this: </p>
  
  <pre><code>trans |&gt; 
    filter(x -&gt; isalpha(x) || isspace(x)) |&gt; 
    map(x -&gt; d[x])
  </code></pre>
  
  <p>This will not work because in Julia the mapping/filter function goes before the iterable. R would solve this by giving you an infix <code>.</code> that you can use, in which case the syntax would look a bit more like: </p>
  
  <pre><code>trans |&gt; 
    filter(x -&gt; isalpha(x) || isspace(x), .) |&gt; 
    map(x -&gt; d[x], .)
  </code></pre>
  
  <p>Is something like this possible in Julia? The <code>|&gt;</code> operator has the potential to clean up long chains of code into neat pipes of operations. A perhaps more Julia-thonic way of a approaching the problem would also be considered an answer to this question. </p>