From: nobu@... Date: 2020-11-30T03:29:31+00:00 Subject: [ruby-core:101150] [Ruby master Feature#17353] Functional chaining operator Issue #17353 has been updated by nobu (Nobuyoshi Nakada). Off topic: fulcanelly (Maks Kompanienko) wrote: > ``` ruby > def handle(requests) = requests > |> Array.filter { not _1.from.user.banned? } > |> Array.map { _1 |> main_router.emit } > |> Array.each &awaiter > > ``` This made me want to disable fluent-dots in endless-def... ---------------------------------------- Feature #17353: Functional chaining operator https://bugs.ruby-lang.org/issues/17353#change-88835 * Author: fulcanelly (Maks Kompanienko) * Status: Open * Priority: Normal ---------------------------------------- Since ruby already moving in that direction(functional), I would like to propose add to it OCaml-like chaining/pipe operator into ruby. Which would allow such syntax ``` ruby def handle(requests) = requests |> Array.filter { not _1.from.user.banned? } |> Array.map { _1 |> main_router.emit } |> Array.each &awaiter ``` What exactly happens here ? Let's look at a bit easier example: ``` ruby gets.to_i |> make_stuff |> format "the number is %d" |> puts ``` Which is expands exactly to the code below ```ruby puts(format("the number is %d", make_stuff(gets.to_i))) ``` So what this operator does is nothing but just tricky form of AST building Advantages: * Increase readability * It's more duck type-ish Limitations: * cant be overloaded -- https://bugs.ruby-lang.org/ Unsubscribe: