MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / fold_left

Method fold_left

functional/pipeline.py:1082–1099  ·  view source on GitHub ↗

Assuming that the sequence elements are of type A, folds from left to right starting with the seed value given by zero_value (of type A) using a function of type func(current: B, next: A) => B. current represents the folded value so far and next is the next element f

(self, zero_value, func)

Source from the content-addressed store, hash-verified

1080 return result_lambda(self.fold_left(seed, func))
1081
1082 def fold_left(self, zero_value, func):
1083 """
1084 Assuming that the sequence elements are of type A, folds from left to right starting with
1085 the seed value given by zero_value (of type A) using a function of type
1086 func(current: B, next: A) => B. current represents the folded value so far and next is the
1087 next element from the sequence to fold into current.
1088
1089 >>> seq('a', 'b', 'c').fold_left(['start'], lambda current, next: current + [next]))
1090 ['start', 'a', 'b', 'c']
1091
1092 :param zero_value: zero value to reduce into
1093 :param func: Two parameter function as described by function docs
1094 :return: value from folding values with func into zero_value from left to right.
1095 """
1096 result = zero_value
1097 for element in self:
1098 result = func(result, element)
1099 return _wrap(result)
1100
1101 def fold_right(self, zero_value, func):
1102 """

Callers 2

aggregateMethod · 0.95
test_fold_leftMethod · 0.80

Calls 1

_wrapFunction · 0.85

Tested by 1

test_fold_leftMethod · 0.64