Class: Enumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/enumerator.rb

Instance Method Summary collapse

Instance Method Details

#compactEnumerator

Create a #compact similar to Array.compact.

Returns:



5
6
7
# File 'lib/ext/enumerator.rb', line 5

def compact
  reject(&:nil?)
end

#uniqEnumerator

Thanks to u/0x0dea for the lazy implementation.

Returns:

See Also:

Author:

  • u/0x0dea



14
15
16
17
18
19
20
# File 'lib/ext/enumerator.rb', line 14

def uniq
  cache = Set.new

  Lazy.new(self) do |yielder, value|
    yielder << value if cache.add?(value)
  end
end