Class: Enumerator
- Inherits:
-
Object
- Object
- Enumerator
- Defined in:
- lib/ext/enumerator.rb
Instance Method Summary collapse
-
#compact ⇒ Enumerator
Create a #compact similar to Array.compact.
-
#uniq ⇒ Enumerator
Thanks to u/0x0dea for the lazy implementation.
Instance Method Details
#compact ⇒ Enumerator
Create a #compact similar to Array.compact.
5 6 7 |
# File 'lib/ext/enumerator.rb', line 5 def compact reject(&:nil?) end |
#uniq ⇒ Enumerator
Thanks to u/0x0dea for the lazy implementation.
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 |