Hacker News new | ask | show | jobs
by kmiroslav 3617 days ago
Doesn't that make the parameter anonymous, though? Can you println that _ and see the value of the current element?
2 comments

Use a function that prints then returns its parameter:

  list(1, 2, 3, 4).reduce{print(_) + _} == 10
Use it if you or your language hasn't defined such a function:

  list(1, 2, 3, 4).reduce{it:= _; println(it); it + _} == 10
In fact, any name for it will do.
Yeah, that's the tradeoff–gain the ability to work with multiple parameters but lose the ability to reuse a single one.