5 ms·
> Elixir's novelty, the pipe operator, is a fantastic approach to working with state in a functional manner. Instead of running readlines(fopen(user_input(), "r
by idobai 10y ago
> Elixir's novelty, the pipe operator, is a fantastic approach to working with state in a functional manner. Instead of running readlines(fopen(user_input(), "r")).uppercase().split(), try the more readable user_input |> fopen("r") |> readlines |> uppercase |> split.
The pipe operator isn't Elixir's "novelty". Also, why is it better than the '.' syntax:
> fromFile(userInput).getLines.map(_.toUpperCase)
Do you get code completion for it as in an oop-ish language?
- andy_ppp 10y agoA |> B |> C second_param Is the same as: C(B(A()), second_param) It's much more powerful than that because you can create chains of functions that pipe their output i.e. Some_data |> fetch_reports |> email_users |> setup_notifications |> IO.inspect |> affirm_elixir_pipes It's 100% not the same as dot or arrow! IO.inspect allows you to print details of any data being passed but also returns the first argument passed. Hope this is a clear explanation of what is happening.
- idobai 10y agoI know how the pipe op works because I've used languages with that operator(f#) but I never had the need for it for ex. in Scala. In Scala a very similar solution has been implemented but nobody uses it.