by sodapopcan · 4y ago · 0 comments
I know Ruby, so here is what I'm used to:
half.map { |i| i + 1 }
I also know Elixir: Enum.map(half, fn i -> i + 1 end)
...and JS, I guess because we have to: half.map(i => i + 1) // It looks just like the Ruby one
...vs whatever the Python version is... I don't know Python very well, but I imagine it involves list comprehensions...Compare all those to the aforementioned D version :
half[] += 1;
I'm really feeling the D version!EDITED to fix little mistakes.
It just seems like a weirdly specific syntactic sugar... which is a "language smell"... to me
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).