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.
For more options, visit https://groups.google.com/d/optout.