cistian.alvarado
2020-1-8 17:31:05

My mind was blown by the pipe operator in Elixir. I felt like it completely solved the annoying problem of these deeply nested function calls I was always running into in lisp languages


cistian.alvarado
2020-1-8 17:31:29

But then I discovered Racket’s threading macros which are the same but way more powerful


cistian.alvarado
2020-1-8 17:31:40

:heart:


sorawee
2020-1-8 18:49:13

threading macro is generally more powerful, but one thing I really like about the pipe operator is that you can add stuff as an afterthought by simply appending text


sorawee
2020-1-8 18:49:39

for threading macro, you need to wrap parentheses around the expression


cistian.alvarado
2020-1-8 18:50:14

Hmm that is true, although it’s still much better than deeply nested functional calls anyday!


willbanders
2020-1-9 05:56:00

So, I’ve used the pipe operator before with both F# and OCaml, but it wasn’t until I spent a lot of time with Elixir that I grew to appreciate it.

From an Object-Oriented perspective, it serves as a bit of a missing link between methods and other functions through UFCS (uniform function call syntax). I’ve used extension methods in Kotlin before for similar things, and I think that’s a much worse alternative by modifying a namespace that doesn’t belong to you. Pipelining can serve as a neat way to break that up while keeping the style of OO method calls without compromising the namespace of the object.