Syntax Proposal - "And-then-style" function-chain call

Since you mentioned |>, Elm has such operator with exactly the same meaning and the symmetric <| one: (quoting from docs/syntax)

In addition to the normal math operations for addition and subtraction, we have the (<|) and (|>) operators. They are aliases for function application, allowing you to write fewer parentheses.

viewNames1 names =
  String.join ", " (List.sort names)

viewNames2 names =
  names
    |> List.sort
    |> String.join ", "

-- (arg |> func) is the same as (func arg)
-- Just keep repeating that transformation!

Historical note: this is borrowed from F#, inspired by Unix pipes.

Relatedly, (<<) and (>>) are function composition operators.

1 Like