< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #17153 has been updated by sawa (Tsuyoshi Sawada).
Hi Ito-san,
This is a duplicate of https://bugs.ruby-lang.org/issues/5663 and https://bugs.ruby-lang.org/issues/15323, and has been realized as `Enumerable#filter_map`.
```ruby
[1, 2, 3, 4, 5].filter_map { |n| n * 10 if n.even? }
#=> [20, 40]
```
----------------------------------------
Feature #17153: Add Enumerable#compact_map
https://bugs.ruby-lang.org/issues/17153#change-87467
* Author: jnchito (Junichi Ito)
* Status: Open
* Priority: Normal
----------------------------------------
I often write code like this (`map`, then `compact`):
``` ruby
nums = [1, 2, 3, 4, 5]
nums.map { |n| n * 10 if n.even? }.compact
#=> [20, 40]
```
Or like this:
``` ruby
nums.select(&:even?).map { |n| n * 10 }
#=> [20, 40]
```
I think it would be very useful and simpler if we could do it by calling one method:
``` ruby
nums.compact_map { |n| n * 10 if n.even? }
#=> [20, 40]
```
How about introducing `Enumerable#compact_map` ?
--
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>