Class: Mayak::Lazy
- Inherits:
-
Object
- Object
- Mayak::Lazy
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/mayak/lazy.rb
Constant Summary collapse
- Value =
type_member
Class Method Summary collapse
- .combine_five(first, second, third, fourth, fifth, &blk) ⇒ Object
- .combine_four(first, second, third, fourth, &blk) ⇒ Object
- .combine_many(lazies, initial, &blk) ⇒ Object
- .combine_seven(first, second, third, fourth, fifth, sixth, seventh, &blk) ⇒ Object
- .combine_six(first, second, third, fourth, fifth, sixth, &blk) ⇒ Object
- .combine_three(first, second, third, &blk) ⇒ Object
- .combine_two(first, second, &blk) ⇒ Object
- .sequence(lazies) ⇒ Object
Instance Method Summary collapse
- #combine(another, &blk) ⇒ Object
- #flat_map(&blk) ⇒ Object
-
#initialize(&blk) ⇒ Lazy
constructor
A new instance of Lazy.
- #map(&blk) ⇒ Object
- #value ⇒ Object
Constructor Details
Class Method Details
.combine_five(first, second, third, fourth, fifth, &blk) ⇒ Object
195 196 197 198 199 |
# File 'lib/mayak/lazy.rb', line 195 def self.combine_five(first, second, third, fourth, fifth, &blk) ::Mayak::Lazy[T.type_parameter(:ResultValue)].new do blk.call(first.value, second.value, third.value, fourth.value, fifth.value) end end |
.combine_four(first, second, third, fourth, &blk) ⇒ Object
162 163 164 165 166 |
# File 'lib/mayak/lazy.rb', line 162 def self.combine_four(first, second, third, fourth, &blk) ::Mayak::Lazy[T.type_parameter(:ResultValue)].new do blk.call(first.value, second.value, third.value, fourth.value) end end |
.combine_many(lazies, initial, &blk) ⇒ Object
288 289 290 291 292 |
# File 'lib/mayak/lazy.rb', line 288 def self.combine_many(lazies, initial, &blk) ::Mayak::Lazy[T.type_parameter(:Result)].new do lazies.reduce(initial) { |acc, element| blk.call(acc, element.value) } end end |
.combine_seven(first, second, third, fourth, fifth, sixth, seventh, &blk) ⇒ Object
270 271 272 273 274 |
# File 'lib/mayak/lazy.rb', line 270 def self.combine_seven(first, second, third, fourth, fifth, sixth, seventh, &blk) ::Mayak::Lazy[T.type_parameter(:ResultValue)].new do blk.call(first.value, second.value, third.value, fourth.value, fifth.value, sixth.value, seventh.value) end end |
.combine_six(first, second, third, fourth, fifth, sixth, &blk) ⇒ Object
231 232 233 234 235 |
# File 'lib/mayak/lazy.rb', line 231 def self.combine_six(first, second, third, fourth, fifth, sixth, &blk) ::Mayak::Lazy[T.type_parameter(:ResultValue)].new do blk.call(first.value, second.value, third.value, fourth.value, fifth.value, sixth.value) end end |
.combine_three(first, second, third, &blk) ⇒ Object
132 133 134 135 136 |
# File 'lib/mayak/lazy.rb', line 132 def self.combine_three(first, second, third, &blk) ::Mayak::Lazy[T.type_parameter(:ResultValue)].new do blk.call(first.value, second.value, third.value) end end |
Instance Method Details
#combine(another, &blk) ⇒ Object
68 69 70 71 72 |
# File 'lib/mayak/lazy.rb', line 68 def combine(another, &blk) ::Mayak::Lazy[T.type_parameter(:NewValue)].new do blk.call(value, another.value) end end |
#flat_map(&blk) ⇒ Object
53 54 55 |
# File 'lib/mayak/lazy.rb', line 53 def flat_map(&blk) ::Mayak::Lazy.new { blk.call(value).value } end |
#map(&blk) ⇒ Object
40 41 42 |
# File 'lib/mayak/lazy.rb', line 40 def map(&blk) ::Mayak::Lazy.new { blk.call(value) } end |
#value ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/mayak/lazy.rb', line 21 def value if @forced T.must(@value) else @forced = true @value = @thunk.call @value end end |