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

Method sum

functional/pipeline.py:1007–1023  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 4

test_initsMethod · 0.80
test_tailsMethod · 0.80
test_sumMethod · 0.80
test_custom_functionsMethod · 0.80

Calls 1

mapMethod · 0.95

Tested by 4

test_initsMethod · 0.64
test_tailsMethod · 0.64
test_sumMethod · 0.64
test_custom_functionsMethod · 0.64