2 ms·
> There's no language in which you would be able to write a function for arbitrary data structures using sum(), and get a reasonable outcome. Computing the num
by naasking 6y ago
> There's no language in which you would be able to write a function for arbitrary data structures using sum(), and get a reasonable outcome.
Computing the number of bytes used by a data type seems perfectly reasonable use of sum in that context. This is also achievable in many languages. All 'sum' needs is a map from a value to a number, which can have many sensible meanings even for arbitrary data types.
- dragonwriter 6y agoAnd that works in python to, even if the source type is strings: sum(map(mappingFunction, iterable)) works fine as long as mappingFunction maps the elements of an iterable to numbers.