Skip to content

Instantly share code, notes, and snippets.

@hackling
Created March 24, 2016 00:00
Show Gist options
  • Save hackling/5058701583512b00a1ce to your computer and use it in GitHub Desktop.
Save hackling/5058701583512b00a1ce to your computer and use it in GitHub Desktop.

So here is a bit of a complicated ruby function

function4(
  function3(
    function2(
      function1,
      value,
    ),
    value,
    value,
  )
)

Elixir has this _fantastic pipe operator, that allows you to construct stuff so that you can read it logically in steps, rather than then from the inside out, which is kind of nice.

function1
|> function2(value)
|> function3(value, value)
|> function4

Except, this is garbage. You ask anyone who knows nothing about the language, and they'll tell you the arity of function2 about is \1. Even worse, they'll get confused about function 4, which looks like it has no arity. Exilir cares about function arity.

function2(value) # this

function1
|> function2(value) # is not the same at this
function1 # this

function0
|> function1 # is not the same as this

If you care about function arity, why are you trying to hide it? Why not something like this?

function1
|> function2(_, value)
|> function3(_, value, value)
|> function4(_)

You can still easily see that the arity is \2 or \3 and the _ can represent the-output-of-the-previous-function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment