Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, it's not like map.

Map builds a new collection based on the function you provide it. At the end of a map call you end up with a potentially transformed collection instance.



You should consider change your tone when you talk to people. It is quite rude.

It is not a map and it is not a forEach, that is why they created it.

> At the end of a map call you end up with a potentially transformed collection instance

The difference between onEach and map is that map returns a new collection that can have different type of elements. But onEach can modify the internal state of the objects when applied. Also onEach is lazy and map is not lazy in kotlin (as far as I know).

Why did I make the comparison with map and not with forEach? Because forEach is basically a translation of a for and map is a functional function and onEach it is also a functional function. You can agree or disagree with my way of trying to explain things, but being rude in your comments saying you are not right (when I know) and them providing another solution that you also know it isn't right, feels like a troll comment.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: