3 ms·
Sorry I should have been more clear. Incrementing every element in an array is much less useful than ".map()" which can execute a function on every element. It
by gitgud 5y ago
Sorry I should have been more clear. Incrementing every element in an array is much less useful than ".map()" which can execute a function on every element.
It just seems like a weirdly specific syntactic sugar... which is a "language smell"... to me
- schveiguy 5y agoYou can use arrays as if they were individual operands, and it will expand out the loop and apply the expression to all the values (and can use optimization/vector tricks if posssible). e.g.: arr1[] += arr2[] / 10.0 + 5; TBH, I don't use this feature much, because I work with ranges more than arrays, which do not have this ability. This feature predates ranges (and the std.algorithm.map function, which can do what you say as well).
- destructionator 5y agoWell you can also just call .map if you want. The nice thing about the [] operation is the compiler can optimize it more heavily since it is restricted to simpler instructions.