@@ -52,11 +52,12 @@ def foldl(f, init=None):
5252 using passed function as reducer.
5353
5454 Usage:
55- >>> print foldl(_ + _)([0,1,2,3,4])
56- 10
57- >>> print foldl(_ * _, 1)([1,2,3])
58- 6
55+ >>> print foldl(_ + _)([0,1,2,3,4])
56+ 10
57+ >>> print foldl(_ * _, 1)([1,2,3])
58+ 6
5959 """
60+
6061 def fold (it ):
6162 args = [f , it ]
6263 if init is not None :
@@ -72,9 +73,10 @@ def foldr(f, init=None):
7273 from iterator from right-to-left).
7374
7475 Usage:
75- >>> print foldr(call, 10)([lambda s: s**2, lambda k: k+10])
76- 400
76+ >>> print foldr(call, 10)([lambda s: s**2, lambda k: k+10])
77+ 400
7778 """
79+
7880 def fold (it ):
7981 args = [flip (f ), reversed (it )]
8082 if init is not None :
@@ -88,15 +90,17 @@ def unfold(f):
8890 """Return function to unfold value into stream using
8991 passed function as values producer. Passed function should
9092 accept current cursor and should return:
93+
9194 * tuple of two elements (value, cursor), value will be added
9295 to output, cursor will be used for next function call
9396 * None in order to stop producing sequence
9497
9598 Usage:
96- >>> doubler = unfold(lambda x: (x*2, x*2))
97- >>> list(islice(doubler(10), 0, 10))
98- [20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]
99+ >>> doubler = unfold(lambda x: (x*2, x*2))
100+ >>> list(islice(doubler(10), 0, 10))
101+ [20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]
99102 """
103+
100104 def _unfolder (start ):
101105 value , curr = None , start
102106 while 1 :
0 commit comments