You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
545 B

  1. # frozen_string_literal: true
  2. module Enumerable
  3. # TODO: Remove this once stop to support Ruby 2.6
  4. if RUBY_VERSION < '2.7.0'
  5. def filter_map
  6. if block_given?
  7. result = []
  8. each do |element|
  9. res = yield element
  10. result << res if res
  11. end
  12. result
  13. else
  14. Enumerator.new do |yielder|
  15. result = []
  16. each do |element|
  17. res = yielder.yield element
  18. result << res if res
  19. end
  20. result
  21. end
  22. end
  23. end
  24. end
  25. end