Class: SequenceEnumerator

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/utilrb/enumerable/sequence.rb

Overview

An enumerator which iterates on multiple iterators in sequence

([1, 2].enum_for + [2, 3].enum_for).to_a # => [1, 2, 2, 3]

See also Enumerable::Enumerator#+

Instance Method Summary collapse

Methods included from Enumerable

#each_uniq, #random_element

Constructor Details

#initializeSequenceEnumerator

Returns a new instance of SequenceEnumerator.



9
# File 'lib/utilrb/enumerable/sequence.rb', line 9

def initialize; @sequence = Array.new end

Instance Method Details

#+(other) ⇒ Object



11
# File 'lib/utilrb/enumerable/sequence.rb', line 11

def +(other); SequenceEnumerator.new << self << other end

#<<(other) ⇒ Object

Adds object at the back of the sequence



13
# File 'lib/utilrb/enumerable/sequence.rb', line 13

def <<(other); @sequence << other; self end

#eachObject



15
16
17
18
# File 'lib/utilrb/enumerable/sequence.rb', line 15

def each
	@sequence.each { |enum| enum.each { |o| yield(o) } } if block_given?
	self
end