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

Doesn't the fact that flatten by default only flattens one level mean you can still create nested output by emitted nested outputs?


Yes, it appears so. From MDN:

> The flatMap() method first maps each element using a mapping function, then flattens the result into a new array. It is identical to a map() followed by a flat() of depth 1, but flatMap() is often quite useful, as merging both into one method is slightly more efficient.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


FlatMap is often most useful when recursing, in my experience.


I have used recursion two times irl outside of interviews.


Used with flatMap, it's a terribly good way of doing something to everything over an arbitrary object and all it's deep values. I do something like this every month or so.

It's one of those tricks you use a lot once you've seen the problems it's applicable to.




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

Search: