app/server/vendor/hamster/lib/hamster/list.rb
# Turn an enumerator into a Hamster list
#
# The result is a lazy collection where the values are memoized as they are
# generated.
#
# @example
#   def rg ; loop { yield rand(100) } ; end
#   Hamster.enumerate(to_enum(:rg)).take(10)
#
# @param enum [Enumerator] The object to iterate over
# @return [Stream]
#
# @api public
Turn an enumerator into a Hamster list
The result is a lazy collection where the values are memoized as they are
generated.
Turn an enumerator into a Hamster list The result is a lazy collection where the values are memoized as they are generated .
def enumerate(enum)
      Stream.new do
        begin
          Sequence.new(enum.next, enumerate(enum))
        rescue StopIteration
          EmptyList
        end
      end
    end
def enumerate ( enum ) Stream . new do begin Sequence . new ( enum . next , enumerate ( enum ) ) rescue StopIteration EmptyList end end end
Turn an enumerator into a Hamster list
The result is a lazy collection where the values are memoized as they are
generated.
Turn an enumerator into a Hamster list The result is a lazy collection where the values are memoized as they are generated .
None
Stream
enum
The object to iterate over
The object to iterate over
example
def rg ; loop { yield rand(100) } ; end Hamster.enumerate(to_enum(:rg)).take(10)
def rg ; loop { yield rand ( 100 ) } ; end Hamster . enumerate ( to_enum ( : rg )) . take ( 10 )
api
None