re: Everything You Need to Know About Array#reduce VIEW POST


Nice explanation. It is unfortunate that the language must reduce into a new array. D uses the concept called a range, filter and map do not reduce to an array. Instead they are a range the applies on another range. This means map and filter can be applied with (multiple times) and it is still O(n).


Just read about it. Ranges look really useful!


It is funny because Ranges a close to c# LINQ or Java stream. D got to really build its algorithms around it (well technically many types of ranges).

Though coding with lazy evaluation can have its surprises when you're not always aware of the implications.

For example several grouping functions, like chunkBy, require the range to be sorted by the grouping. Sorting is eager, but grouping doesn't need to be. And you can group an unsorted range which could have value... Maybe.

code of conduct - report abuse