Implement `filter_map` from Ruby2.6.
MODIFY
mrbgems/mruby-enum-ext/mrblib/enum.rb
mrbgems/mruby-enum-ext/mrblib/enum.rb
@@ -826,5 +826,17 @@ module Enumerable
end
hash.values
end
+
+ def filter_map(&blk)
+ return to_enum(:find_index, val) unless blk
+
+ ary = []
+ self.each do |x|
+ x = blk.call(x)
+ ary.push x if x
+ end
+ ary
+ end
+
alias filter select
end

MODIFY
mrbgems/mruby-enum-ext/test/enum.rb
mrbgems/mruby-enum-ext/test/enum.rb
@@ -188,3 +188,8 @@ assert("Enumerable#to_h") do
assert_equal h0, h
assert_equal({1=>4,3=>8}, c.new.to_h{|k,v|[k,v*2]})
end
+
+
+assert("Enumerable#filter_map") do
+ assert_equal [4, 8, 12, 16, 20], (1..10).filter_map{|i| i * 2 if i%2==0}
+end

Implement `filter_map` from Ruby2.6.