From d4bbb52e88558f9938004f9a12398aef8d8eb5ba Mon Sep 17 00:00:00 2001 From: Lillian Zhang Date: Wed, 11 Nov 2020 11:51:20 -0500 Subject: [PATCH 1/2] Implement and untag Enumerable#filter_map --- spec/tags/core/enumerable/filter_map_tags.txt | 3 --- src/main/ruby/truffleruby/core/enumerable.rb | 13 +++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) delete mode 100644 spec/tags/core/enumerable/filter_map_tags.txt diff --git a/spec/tags/core/enumerable/filter_map_tags.txt b/spec/tags/core/enumerable/filter_map_tags.txt deleted file mode 100644 index 09b6dd0d9d5a..000000000000 --- a/spec/tags/core/enumerable/filter_map_tags.txt +++ /dev/null @@ -1,3 +0,0 @@ -fails:Enumerable#filter_map returns an empty array if there are no elements -fails:Enumerable#filter_map returns an array with truthy results of passing each element to block -fails:Enumerable#filter_map returns an enumerator when no block given diff --git a/src/main/ruby/truffleruby/core/enumerable.rb b/src/main/ruby/truffleruby/core/enumerable.rb index 88b0aa054b69..15cbbcf23d5f 100644 --- a/src/main/ruby/truffleruby/core/enumerable.rb +++ b/src/main/ruby/truffleruby/core/enumerable.rb @@ -924,6 +924,19 @@ def reject ary end + def filter_map + return to_enum(:filter_map) { enumerator_size } unless block_given? + + ary = [] + each do + o = Primitive.single_block_arg + v = yield(o) + ary << v if v + end + + ary + end + def reverse_each(&block) return to_enum(:reverse_each) { enumerator_size } unless block_given? From 397abe2b5b0143081a8464b03e549648fe860275 Mon Sep 17 00:00:00 2001 From: Lillian Zhang Date: Wed, 11 Nov 2020 11:58:54 -0500 Subject: [PATCH 2/2] changelog entry for Enumerable#tally and #filter_map --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e14fd114414..97be784f1715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Compatibility: * Implement `String#undump` (#2131, @kustosz) * `Errno` constants with the same `errno` number are now the same class. +* Implement `Enumerable#tally` and `Enumerable#filter_map` (#2144 and #2152, @LillianZ). Performance: