From: jonathan@... Date: 2019-05-19T22:05:06+00:00 Subject: [ruby-core:92725] [Ruby trunk Feature#15799] pipeline operator Issue #15799 has been updated by jonathanhefner (Jonathan Hefner). Eregon (Benoit Daloze) wrote: > Also, if we actually introduce a pipeline operator, I think it's much more useful to have Elixir semantics of passing the result as the first argument of the RHS, than just a different syntax for `.`. I agree that the pipeline operator should introduce new semantics, instead of being an alias of `.`. While Elixir uses `|>` to insert a first argument to the RHS, F# and Elm use `|>` to append a last argument to the RHS (due to different conventions regarding function parameter order). One use-case for such "last argument" behavior in Ruby is file IO: ```ruby File.read("file.txt").gsub(/foo/, "bar") |> File.write "file.txt" ``` Of course it gets tricky when option arguments are involved. But perhaps kwargs could be handled specially, such that the LHS of `|>` is inserted before them. For example, the following would both work as expected: ```ruby File.read("other.txt") |> File.write "file.txt", mode: "a" ``` ```ruby File.read("other.txt") |> File.write "file.txt", **options ``` ---------------------------------------- Feature #15799: pipeline operator https://bugs.ruby-lang.org/issues/15799#change-78084 * Author: nobu (Nobuyoshi Nakada) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Implemented the pipeline operator `|>`, a topic of "ruby committers vs the world" in RubyKaigi 2019. Also a casual idea of rightward assignment. ```ruby 1.. |> take 10 |> map {|x| x*2} |> (x) p x #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] ``` https://github.com/nobu/ruby/tree/feature/pipeline -- https://bugs.ruby-lang.org/ Unsubscribe: