class Enumerator

Public Instance Methods

compact() click to toggle source

Create a compact similar to {Array.compact}.

@return [Enumerator] with {nil}s removed

# File lib/ext/enumerator.rb, line 5
def compact
  reject(&:nil?)
end
uniq() click to toggle source

Thanks to u/0x0dea for the lazy implementation.

@author u/0x0dea @see www.reddit.com/r/ruby/comments/37jpnz/is_this_the_best_laziest_way_to_add_compact_and/crnckrv Discussion thread @return [Enumerator] only my unique elements

# 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