Re:Ask HN: Your favorite syntactic sugar from any language?
by nicoburns on Friday June 15, 2018 @07:19PM
(#17324562)
JavaScript lets you do:
a.map(x => x + 1)
which is pretty nice. And Rust lets you do:
a.map(|x| x + 1)
C++ syntax is just awful, and especially for functional stuff.
Re:Ask HN: Your favorite syntactic sugar from any language?
by himom on Friday June 15, 2018 @08:29PM
(#17324939)
Swift closure syntax, at least in <= 2.0, made for awkward API calls, since it wasn’t clear whether inline or after closures were used.
In Ruby,
a.map(&:succ)
Re:Ask HN: Your favorite syntactic sugar from any language?
by steveklabnik on Friday June 15, 2018 @08:36PM
(#17324981)
If you have a named function, rust lets you do
a.map(succ)
as well, since functions can be used where closures can, as long as the types work.
Re:Ask HN: Your favorite syntactic sugar from any language?
by jeffmcmahan on Friday June 15, 2018 @08:51PM
(#17325062)
Same in JS
Re:Ask HN: Your favorite syntactic sugar from any language?
by stochastic_monk on Friday June 15, 2018 @07:06PM
(#17324481)
You're really looking for `std::transform`. On the other hand,
for(auto it(a.start()); it < a.end(); ++(*it++));
and for(auto &el: a) ++el;
aren't terribly verbose.
Re:Ask HN: Your favorite syntactic sugar from any language?
by erik_seaberg on Friday June 15, 2018 @10:04PM
(#17325369)
I'm still surprised Haskell is the only language I've ever seen in which the "add 1 to your argument" function is simply
(+ 1)
If I need a quick-and-dirty map over a list of something, a
is much nicer than a or whatnot that I have to do in C++.