4 ms·
I think the concept of piping is actually more similar to function(function()) than .method().method(), because you're not limited to the scope of your initial
by yoavm 9y ago
I think the concept of piping is actually more similar to function(function()) than .method().method(), because you're not limited to the scope of your initial object's methods.
And the truth is that functionB(functionA()) reads much worse than functionA | functionB , so yeah I agree that this is something that shell scripting languages got right.
- yellowapple 9y agoFor reference, various functional languages do indeed treat something like 'foo |> bar' as equivalent to 'bar(foo)' (I've used this extensively in Elixir, where it's standard practice; I'm pretty sure this is derived from F# and/or Clojure, both of which - IIRC - use the same operator for the same purpose). It's not really perfect parity with what a shell typically offers, though, since a shell's pipeline steps (usually) run in parallel and indefinitely, consuming an input stream and producing an output stream (whether those streams are text, rich objects, audio/video data, or something else entirely). Elixir/Erlang are well-suited to achieving that parity by spinning up processes and using message passing for I/O, but Elixir's pipeline operator doesn't really do that (last I checked).
- michaelmrose 9y agoClojure has threading macros that turn (function(function(function) into (-> function function function) An interesting take on that is a library called swiss arrows that lets you do (-<> (function arg1 <>) (function <> arg2) (function arg1 arg2 <>) Using the <> to indicate where the result of calling one shall be threaded into the next.
- robto 9y agoThat's in the standard library, actually. It's called as->. (as-> value <> (function1 arg1 <>) (function <> arg2) (function arg1 arg2 <>))
- michaelmrose 9y agoFound the old swiss arrows and didn't realize that as-> even existed thank you.