Class: Fairy::PGroupBy::KeyValueStream
- Inherits:
-
Object
- Object
- Fairy::PGroupBy::KeyValueStream
- Includes:
- Enumerable
- Defined in:
- lib/fairy/node/p-group-by.rb
Constant Summary collapse
- EOS =
:__KEY_VALUE_STREAM_EOS__
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #concat(elements) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(key, generator) ⇒ KeyValueStream
constructor
A new instance of KeyValueStream.
- #push(e) ⇒ Object (also: #enq)
- #push_eos ⇒ Object
- #shift ⇒ Object (also: #deq, #pop)
- #size ⇒ Object
Constructor Details
#initialize(key, generator) ⇒ KeyValueStream
Returns a new instance of KeyValueStream.
132 133 134 135 |
# File 'lib/fairy/node/p-group-by.rb', line 132 def initialize(key, generator) @key = key @buf = [] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
137 138 139 |
# File 'lib/fairy/node/p-group-by.rb', line 137 def key @key end |
Instance Method Details
#concat(elements) ⇒ Object
148 149 150 |
# File 'lib/fairy/node/p-group-by.rb', line 148 def concat(elements) @buf.concat elements end |
#each(&block) ⇒ Object
161 162 163 164 165 |
# File 'lib/fairy/node/p-group-by.rb', line 161 def each(&block) while (v = shift) != EOS block.call v end end |
#push(e) ⇒ Object Also known as: enq
139 140 141 |
# File 'lib/fairy/node/p-group-by.rb', line 139 def push(e) @buf.push e end |
#push_eos ⇒ Object
144 145 146 |
# File 'lib/fairy/node/p-group-by.rb', line 144 def push_eos push EOS end |
#shift ⇒ Object Also known as: deq, pop
152 153 154 155 156 157 |
# File 'lib/fairy/node/p-group-by.rb', line 152 def shift while @buf.empty? Fiber.yield end @buf.shift end |
#size ⇒ Object
167 168 169 170 171 |
# File 'lib/fairy/node/p-group-by.rb', line 167 def size c = 0 each{|v| c += 1} c end |