some_array |> do_thing() |> do_another_thing() |> do_something_else()
Even though Elixir is functional and aggressively not object oriented, if you squint at this pattern you get the readability of an OO-style method chaining API.
some_array |> do_thing() |> do_another_thing() |> do_something_else()
Even though Elixir is functional and aggressively not object oriented, if you squint at this pattern you get the readability of an OO-style method chaining API.
See also:
https://mamememo.blogspot.com/2019/06/a-brief-history-of-pip...
``` 1.. |> take 10 |> map {|e| e2} |> (x) ```
which is equivalent to
``` (1...).take(10).map{|e| e2} ```
So in order to use it you still need extensions on every single object. The only reason that looks nice is because in this example you continuously call methods on lists that return a list. You can't add `my_custom_list_operation(list_input)` in between.
Going forward, the pipe operator is going to be showing up in many new languages. I've used elixir a lot, and the pipe operator is a genius piece of syntactic sugar.
some_array
|> do_thing()
|> do_another_thing()
|> do_something_else()a.this().that() requires that a.this() returns an object on which .that() can be invoked.
(that (this a)) requires that (this a) returns an object that is a suitable argument to that.
"string".do_stuff() - do_stuff() is a method on the "string" class, with all of the potential gotchas that might come with an OO implementation. Does the method mutate the internal state of the object? Does the particular class override the default implementation? Is it a monkey-patched implementation (the issue raised by this article)?
"string" |> do_stuff() - do_stuff() is a standalone pure function. The data is immutable and does exactly what it says.