[#100689] [Ruby master Feature#17303] Make webrick to bundled gems or remove from stdlib — hsbt@...
Issue #17303 has been reported by hsbt (Hiroshi SHIBATA).
11 messages
2020/11/02
[#100852] [Ruby master Feature#17326] Add Kernel#must! to the standard library — zimmerman.jake@...
Issue #17326 has been reported by jez (Jake Zimmerman).
24 messages
2020/11/14
[#100930] [Ruby master Feature#17333] Enumerable#many? — masafumi.o1988@...
Issue #17333 has been reported by okuramasafumi (Masafumi OKURA).
10 messages
2020/11/18
[#101071] [Ruby master Feature#17342] Hash#fetch_set — hunter_spawn@...
Issue #17342 has been reported by MaxLap (Maxime Lapointe).
26 messages
2020/11/25
[ruby-core:101142] [Ruby master Feature#17353] Functional chaining operator
From:
zverok.offline@...
Date:
2020-11-29 18:32:10 UTC
List:
ruby-core #101142
Issue #17353 has been updated by zverok (Victor Shepelev).
"Let's take `|>` from Elixir" is proposed roughly once a month. The problem with this proposal is that it doesn't work well with Ruby syntax. Ruby's core chaining module is `Enumerable` ("core" in the sense it shows how the things are designed here), and core chainable item is block.
So let's look at your example:
```ruby
def handle(requests) = requests
|> Array.filter { not _1.from.user.banned? }
|> Array.map { _1 |> main_router.emit }
|> Array.each &awaiter
```
There is no way (besides "it is Elegant Because It Is Elegant In Elixir") how exactly it is better than
```ruby
def handle(requests) = requests
.filter { not _1.from.user.banned? }
.map { main_router.emit(_1) }
.each &awaiter
```
Now, this (one-item chaining):
```ruby
gets.to_i
|> make_stuff
|> format "the number is %d"
|> puts
```
is handled by [Object#then](https://ruby-doc.org/core-2.7.0/Object.html#method-i-then), existing since 2.6:
```ruby
gets.to_i
.then(&method(:make_stuff))
.then { format "the number is %d", _1 }
.then(&method(:puts))
```
Which is exactly "ideologically compatible" with how Enumerable chaining works, trivially implemented and place nice with all possible Ruby intuitions.
Now, method references and currying is another, sadder, story, but it would be sad with any chaining syntax.
----------------------------------------
Feature #17353: Functional chaining operator
https://bugs.ruby-lang.org/issues/17353#change-88823
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>