Class: Enumerator::Lazy
- Inherits:
-
Object
- Object
- Enumerator::Lazy
- Defined in:
- lib/twterm/extensions/enumerator/lazy.rb
Instance Method Summary collapse
Instance Method Details
#scan(initial, sym = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/twterm/extensions/enumerator/lazy.rb', line 3 def scan(initial, sym = nil) acc = initial @_scan_has_yielded_initial_value = false Enumerator::Lazy.new(self) do |y, x| y << initial && @_scan_has_yielded_initial_value = true unless @_scan_has_yielded_initial_value acc = sym.nil? ? yield(acc, x) : sym.to_proc.call(acc, x) y << acc end end |