What. Python's `sum()` works on anything that defines `__add__`, which can be numbers, strings, lists, or your own custom classes.
sum([[1, 2], [3, 4]], []) == [1, 2, 3, 4] sum([[1, 2], [3, 4]], []) == [1, 2, 3, 4]
I use Joda Money and frequently find myself doing:
If you don't pass in a baseline, you get optional: Also, StreamEx improves the ergonomics of Java streams. The way I would implement the original example: Unfortunately BigDecimal is not especially ergonomic (it could use a `multiply(long)` method, which would eliminate the annoying `mapValue()` above). But unlike the python version of this, it will preserve scale. And streams work as-is on Money types.