[#68137] improve semantics of manpages — "Anthony J. Bentley" <anthony@...>
Hi,
1 message
2015/02/17
[#68144] Re: Future of test suites for Ruby — Anthony Crumley <anthony.crumley@...>
FYI...
4 messages
2015/02/17
[#68343] [Ruby trunk - Bug #10916] [Open] What the Ruby? SegFault? — ruby@...
Issue #10916 has been reported by why do i need this acct just to create a bug report.
5 messages
2015/02/27
[#68373] Re: [Ruby trunk - Bug #10916] [Open] What the Ruby? SegFault?
— "Martin J. Dürst" <duerst@...>
2015/03/02
> * Author: why do i need this acct just to create a bug report
[#68358] [Ruby trunk - Bug #10902] require("enumerator") scans LOAD_PATH 2x on every invocation — ruby@...1.net
Issue #10902 has been updated by Aman Gupta.
3 messages
2015/02/28
[ruby-core:68083] [Ruby trunk - Feature #5663] Combined map/select method
From:
wvvwwvw@...
Date:
2015-02-10 22:30:22 UTC
List:
ruby-core #68083
Issue #5663 has been updated by Andrew Ledvina.
~~~
The only caveat is that it would be impossible to intentionally return nil here
~~~
I don't see why you need that, just have the block return a pair `(keep_if_true, mapped_value)`. I also would second the name `filter_map`. Ignoring all edge-cases you could just do something like:
```
module Array
def filter_map
result = []
self.each do |elem|
keep, value = yield elem
result << value if keep
end
result
end
end
> [1,32,9,33,2,13].filter_map{|v| [v < 20, v%2==1 ? v*2 : nil]]}
=> [2, 18, nil, 26]
```
Although to be fair, `filter_map` is just `reduce` with a more complicated block
```
> [1,32,9,33,2,13].reduce([]){|acc, v| v<20 ? v%2==1 ? acc << v*2 : acc << nil : nil; acc}
=> [2, 18, nil, 26]
```
----------------------------------------
Feature #5663: Combined map/select method
https://bugs.ruby-lang.org/issues/5663#change-51466
* Author: Yehuda Katz
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
It is pretty common to want to map over an Enumerable, but only include the elements that match a particular filter. A common idiom is:
enum.map { |i| i + 1 if i.even? }.compact
It is of course also possible to do this with two calls:
enum.select { |i| i.even? }.map { |i| i + 1 }
Both cases are clumsy and require two iterations through the loop. I'd like to propose a combined method:
enum.map_select { |i| i + 1 if i.even? }
The only caveat is that it would be impossible to intentionally return nil here; suggestions welcome. The naming is also a strawman; feel free to propose something better.
--
https://bugs.ruby-lang.org/