Sha256: eae160fabadd8fd93bee037c8e9a4d10781d44fdeaf9a7b442bb12b027d64721

Contents?: true

Size: 843 Bytes

Versions: 25

Compression:

Stored size: 843 Bytes

Contents

# frozen_string_literal: true

# Refine Array seprately, 'cause refining modules is vulnerable to prepend:
# - https://bugs.ruby-lang.org/issues/13446
RubyNext::Core.patch Enumerable, method: :filter_map, version: "2.7", refineable: [Enumerable, Array] do
  <<-RUBY
def filter_map
  if block_given?
    result = []
    each do |element|
      res = yield element
      result << res if res
    end
    result
  else
    Enumerator.new do |yielder|
      result = []
      each do |element|
        res = yielder.yield element
        result << res if res
      end
      result
    end
  end
end
  RUBY
end

RubyNext::Core.patch Enumerator::Lazy, method: :filter_map, version: "2.7" do
  <<-RUBY
def filter_map
  Enumerator::Lazy.new(self) do |yielder, *values|
    result = yield(*values)
    yielder << result if result
  end
end
  RUBY
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ruby-next-core-1.1.0 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-1.0.3 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-1.0.2 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-1.0.1 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-1.0.0 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-1.0.0.rc.1 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.15.3 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.15.2 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.15.1 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.15.0 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.14.1 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.14.0 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.13.3 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.13.2 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.13.1 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.13.0 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.12.0 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.11.1 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.11.0 lib/ruby-next/core/enumerable/filter_map.rb
ruby-next-core-0.10.5 lib/ruby-next/core/enumerable/filter_map.rb