File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
spec/tags/core/enumerator
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ Compatibility:
17
17
* Implement ` Enumerable#tally ` and ` Enumerable#filter_map ` (#2144 and #2152 , @LillianZ ).
18
18
* Implement ` Range#minmax ` .
19
19
* Pass more ` Enumerator::Lazy#uniq ` and ` Enumerator::Lazy#chunk ` specs (#2146 , @LillianZ ).
20
+ * Implement ` Enumerator#produce ` (#2160 , @zverok )
20
21
21
22
Performance:
22
23
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -216,6 +216,19 @@ def +(other)
216
216
Enumerator ::Chain . new ( self , other )
217
217
end
218
218
219
+ def self . produce ( initial = nil )
220
+ # Taken from https://github.com/zverok/enumerator_generate
221
+ raise ArgumentError , 'No block given' unless block_given?
222
+ Enumerator . new ( Float ::INFINITY ) do |y |
223
+ val = initial == nil ? yield ( ) : initial
224
+
225
+ loop do
226
+ y << val
227
+ val = yield ( val )
228
+ end
229
+ end
230
+ end
231
+
219
232
class Yielder
220
233
def initialize ( &block )
221
234
raise LocalJumpError , 'Expected a block to be given' unless block_given?
You can’t perform that action at this time.
0 commit comments