ozra / onyx-lang

The Onyx Programming Language
Other
96 stars 5 forks source link

Feature request: pipe operator #34

Open stugol opened 8 years ago

stugol commented 8 years ago

Nicer syntax for calling free functions in a chain. Useful to avoid nested calls. Accepts local free functions, proc objects and blocks.

fn(value) -> value + 1
puts 1 |> fn |> fn |> fn    # outputs 4. Equivalent to fn(fn(fn(1))), and much nicer

Might be redundant if UFCS is implemented. Then again, maybe this is preferable to UFCS. After all, a free function isn't a method, so it might be a good idea to differentiate in this manner. Alternatively, implement both. The |> operator would have a lower precedence than ., so perhaps each one has its merit.