[#102652] [Ruby master Bug#17664] Behavior of sockets changed in Ruby 3.0 to non-blocking — ciconia@...
Issue #17664 has been reported by ciconia (Sharon Rosner).
23 messages
2021/02/28
[ruby-core:102530] [Ruby master Feature#17608] Compact and sum in one step
From:
mame@...
Date:
2021-02-16 11:26:06 UTC
List:
ruby-core #102530
Issue #17608 has been updated by mame (Yusuke Endoh).
I think this is an endless argument. [An idiom "`.compact.max`" is 10x more frequent than "`.compact.sum`"](https://github.com/search?l=Ruby&q=compact.max&type=Code
) in GitHub search. If we introduce `Array#compact_max`, then `#compact_min` and `#compact_minmax` should be also introduced. Next, why don't we need `#compact_max_by`, `#compact_max_by`, and `#compact_minmax_by`? Maybe some people want `#compact_sort_by` eventually.
We have never yet had combination methods `#sort_uniq` and `#zip_map`, which are clearly frequent idioms. You need to prove that `.compact.sum` is really special, e.g., it is a critical performance bottleneck in multiple real-world applications, it is indisputably frequent (like `#filter_map`), it is difficult to work around (like `#flat_map`), etc.
----------------------------------------
Feature #17608: Compact and sum in one step
https://bugs.ruby-lang.org/issues/17608#change-90429
* Author: sawa (Tsuyoshi Sawada)
* Status: Rejected
* Priority: Normal
----------------------------------------
Many use cases of `Array#sum` are preceded with the `compact` method or are followed by a block to ensure the value is addable.
```ruby
a = [1, nil, 2, 3]
a.sum # !> TypeError
a.compact.sum # => 6
a.sum{_1 || 0} # => 6
```
I propose there should be a way to do that in one step. I request either of the following:
A. Change the current behaviour to skip `nil`s.
```ruby
a.sum # => 6
```
B. `Array#filter_sum` method
```ruby
a.filter_sum # => 6
```
C. An option for `Array#sum`
```ruby
a.sum(compact: true) # => 6
```
--
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>