oops...little mistake ... |> (fn content -> File.write! (output_path, content) end).
On Sun, Mar 10, 2019 at 6:40 PM Ricardo Harari <[email protected]> wrote: > Hi Tom > > the order of the argument breaks sometimes and define an auxiliary > function makes the code more readable. > > for this sample you can simplify > > ... > |> (content fn -> File.write! (output_path, content) end). > > but it will be more readable if we can write something like: > > |> File.write! (Output_path, &1) > > with macros you can invent your own pipe > see this project as an inspiration: > https://github.com/ruby2elixir/plumber_girl > > have fun! > > > On Sun, Mar 10, 2019 at 6:37 AM <[email protected]> wrote: > >> The pipeline operator is one of the best features of the language, >> however there are some instances where you want to continue a chain of >> pipelines for clarity but can't because the argument order is not conducive >> to piping. For example here is an example when working with files: >> >> defmodule Chess.PGN do >> def unique_checkmates(input_path, output_path) >> path >> |> File.stream!() >> |> Stream.chunk_every(21) >> |> Stream.filter(fn chunk -> checkmate?(Enum.at(chunk, 17)) end) >> |> Stream.uniq_by(fn chunk -> Enum.at(chunk, 19) end) >> |> Stream.map(fn chunk -> Enum.join(chunk, "") end) >> |> Enum.join("") >> |> write_file(output_path) >> end >> >> def write_file(content, output_path) do >> File.write!(output_path, content) >> end >> end >> >> Instead of having to add a dummy method I would like to double pipe into >> File.write which would be cleaner. >> >> ... >> ||> File.write!(output_path) >> >> I think this could also be extended to triple, and quadruple pipes. Five >> seems like overkill, but I think you could make the argument for arbitrary >> levels of piping. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/c6f02f27-fca4-4d5b-9c88-e966faaf9c0c%40googlegroups.com >> <https://groups.google.com/d/msgid/elixir-lang-core/c6f02f27-fca4-4d5b-9c88-e966faaf9c0c%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CA%2B5LQzMEk9sOjt2oNpJCXZpT5bdA9x5paLSoLSDKX_BDBiB9yg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
