Sha256: bc784fc2d6df760b108f75aec12aa63d3bbef02f5603554a2b9bc2da2c13947f

Contents?: true

Size: 687 Bytes

Versions: 3

Compression:

Stored size: 687 Bytes

Contents

require 'set'

module Polyfill
  module V2_4
    module Enumerator
      module Lazy
        module Instance
          module Uniq
            module Method
              def uniq
                seen = Set.new

                ::Enumerator::Lazy.new(self) do |yielder, *values|
                  result = block_given? ? yield(*values) : values

                  yielder.<<(*values) if seen.add?(result)
                end
              end
            end

            refine ::Enumerator::Lazy do
              include Method
            end

            def self.included(base)
              base.include Method
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polyfill-0.6.0 lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb
polyfill-0.5.0 lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb
polyfill-0.4.0 lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb