Module: DataModeler::Dataset::IteratingBasedOnNext
Overview
Provides ‘#each` (which can return an `Iterator`) and `#to_a` based on `#next`
Instance Method Summary collapse
-
#each ⇒ nil|Iterator
Yields on each [inputs, targets] pair.
-
#map ⇒ Array|Iterator
(also: #collect)
Yields on each ‘[inputs, targets]` pair, collecting the input.
- #to_a ⇒ Array
Instance Method Details
#each ⇒ nil|Iterator
Yields on each [inputs, targets] pair.
42 43 44 45 46 47 |
# File 'lib/data_modeler/dataset/helper.rb', line 42 def each reset_iteration return enum_for(:each) unless block_given? loop { yield self.next } nil end |
#map ⇒ Array|Iterator Also known as: collect
Yields on each ‘[inputs, targets]` pair, collecting the input.
51 52 53 54 55 |
# File 'lib/data_modeler/dataset/helper.rb', line 51 def map reset_iteration return enum_for(:collect) unless block_given? [].tap { |ret| loop { ret << yield(self.next) } } end |
#to_a ⇒ Array
61 62 63 |
# File 'lib/data_modeler/dataset/helper.rb', line 61 def to_a each.to_a end |