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

Method reduce

functional/pipeline.py:928–946  ·  view source on GitHub ↗

Reduce sequence of elements using func. API mirrors functools.reduce >>> seq([1, 2, 3]).reduce(lambda x, y: x + y) 6 :param func: two parameter, associative reduce function :param initial: single optional argument acting as initial value :return: re

(self, func, *initial)

Source from the content-addressed store, hash-verified

926 return self._transform(transformations.count_by_value_t())
927
928 def reduce(self, func, *initial):
929 """
930 Reduce sequence of elements using func. API mirrors functools.reduce
931
932 >>> seq([1, 2, 3]).reduce(lambda x, y: x + y)
933 6
934
935 :param func: two parameter, associative reduce function
936 :param initial: single optional argument acting as initial value
937 :return: reduced value using func
938 """
939 if len(initial) == 0:
940 return _wrap(reduce(func, self))
941 elif len(initial) == 1:
942 return _wrap(reduce(func, self, initial[0]))
943 else:
944 raise ValueError(
945 "reduce takes exactly one optional parameter for initial value"
946 )
947
948 def accumulate(self, func=add):
949 """

Callers 3

productMethod · 0.95
test_reduceMethod · 0.80
test_wrap_pandasMethod · 0.80

Calls 1

_wrapFunction · 0.85

Tested by 2

test_reduceMethod · 0.64
test_wrap_pandasMethod · 0.64