Skip to content

Commit 38c1bdf

Browse files
committed
[GR-19220] Implement and untag Enumerable#filter_map (#2152)
PullRequest: truffleruby/2154
2 parents 2038ab2 + 397abe2 commit 38c1bdf

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Compatibility:
1313

1414
* Implement `String#undump` (#2131, @kustosz)
1515
* `Errno` constants with the same `errno` number are now the same class.
16+
* Implement `Enumerable#tally` and `Enumerable#filter_map` (#2144 and #2152, @LillianZ).
1617

1718
Performance:
1819

spec/tags/core/enumerable/filter_map_tags.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/main/ruby/truffleruby/core/enumerable.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,19 @@ def reject
927927
ary
928928
end
929929

930+
def filter_map
931+
return to_enum(:filter_map) { enumerator_size } unless block_given?
932+
933+
ary = []
934+
each do
935+
o = Primitive.single_block_arg
936+
v = yield(o)
937+
ary << v if v
938+
end
939+
940+
ary
941+
end
942+
930943
def reverse_each(&block)
931944
return to_enum(:reverse_each) { enumerator_size } unless block_given?
932945

0 commit comments

Comments
 (0)