File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
graalpython/lib-graalpython Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -305,3 +305,30 @@ def __setstate__(self, state):
305
305
self .indices [i ] = index
306
306
lst .append (gear [index ])
307
307
self .lst = lst
308
+
309
+
310
+ class accumulate (object ):
311
+ """
312
+ "accumulate(iterable) --> accumulate object
313
+
314
+ Return series of accumulated sums."""
315
+
316
+ def __init__ (self , iterable , func = None ):
317
+ self .iterable = iter (iterable )
318
+ self .func = func
319
+ self .total = None
320
+
321
+ def __iter__ (self ):
322
+ return self
323
+
324
+ def __next__ (self ):
325
+ value = next (self .iterable )
326
+ if self .total is None :
327
+ self .total = value
328
+ return value
329
+
330
+ if self .func is None :
331
+ self .total += value
332
+ else :
333
+ self .total = self .func (total , value )
334
+ return self .total
You can’t perform that action at this time.
0 commit comments