MCPcopy Create free account
hub / github.com/ActiveState/code / reduced

Function reduced

recipes/Python/498264_reduce_as_a_generator/recipe-498264.py:36–53  ·  view source on GitHub ↗

reduced() is complementary to the greduce generator. Use this function to keep the current value of the reduced stream. This is analog to reduce(lst) where reduce() is Pythons builtin reduce and lst is a list.

(stream_red)

Source from the content-addressed store, hash-verified

34
35
36def reduced(stream_red):
37 '''
38 reduced() is complementary to the greduce generator.
39 Use this function to keep the current value of the reduced stream. This
40 is analog to reduce(lst) where reduce() is Pythons builtin reduce and lst
41 is a list.
42 '''
43 res = stream_red.next()
44 if res is None:
45 res = stream_red.throw(YieldResult)
46 stream_red.next()
47 return res
48 for item in stream_red:
49 if item is None:
50 break
51 else:
52 res = item
53 return res
54
55#
56# Example 1

Callers 1

recipe-498264.pyFile · 0.85

Calls 2

nextMethod · 0.45
throwMethod · 0.45

Tested by

no test coverage detected