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)
| 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 | """ |