Takes sum of elements in sequence. >>> seq([1, 2, 3, 4]).sum() 10 >>> seq([(1, 2), (1, 3), (1, 4)]).sum(lambda x: x[0]) 3 :param projection: function to project on the sequence before taking the sum :return: sum of elements in sequence
(self, projection=None)
| 1005 | return self.reduce(mul) |
| 1006 | |
| 1007 | def sum(self, projection=None): |
| 1008 | """ |
| 1009 | Takes sum of elements in sequence. |
| 1010 | |
| 1011 | >>> seq([1, 2, 3, 4]).sum() |
| 1012 | 10 |
| 1013 | |
| 1014 | >>> seq([(1, 2), (1, 3), (1, 4)]).sum(lambda x: x[0]) |
| 1015 | 3 |
| 1016 | |
| 1017 | :param projection: function to project on the sequence before taking the sum |
| 1018 | :return: sum of elements in sequence |
| 1019 | """ |
| 1020 | if projection: |
| 1021 | return sum(self.map(projection)) |
| 1022 | else: |
| 1023 | return sum(self) |
| 1024 | |
| 1025 | def average(self, projection=None): |
| 1026 | """ |