by artemisyna · 8y ago · 0 comments
If I need a quick-and-dirty map over a list of something, a
(\x -> x + 1) a
is much nicer than a std::for_each(a.start(), a.end(),
[](float x) {
return x + 1;
} // end of lambda expression
)
or whatnot that I have to do in C++.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.
In Ruby,
a.map(&:succ) a.map(succ)
as well, since functions can be used where closures can, as long as the types work. for(auto it(a.start()); it < a.end(); ++(*it++));
and for(auto &el: a) ++el;
aren't terribly verbose. (+ 1)