Comment by robot-wrangler

4 days ago

>> I would consider the R code to be slightly easier to read (notice how many quotes and brackets the Python code needs)

Oh god no, do people write R like that, pipes at the end? Elixir style pipe-operators at the beginning is the way.

And if you really wanted to "improve" readability by confusing arguments/functions/vars just to omit quotes, python can do that, you'll just need a wrapper object and getattr hacks to get from `my_magic_strings.foo` -> `'foo'`. As for the brackets.. ok that's a legitimate improvement, but again not language related, it's library API design for function sigs.

The right way is putting the pipe operator at the beginning of the expression.

  (-> (gather-some-data)
    (map 'Vector #'some-functor)
    (filter #'some-predicate)
    (reduce #'some-gatherer))

Or for those who have an irrational fear of brackets:

  ->
    gather-some-data
    map 'Vector #'some-functor
    filter #'some-predicate
    reduce #'some-gatherer

IIRC, putting pipe operator `|>` at end of line prevents the expression from terminating early. Otherwise the newline would terminate it.