You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With flatMap added with flat to reduce iterations and allocations, it would be nice to have an accompanying filterMap method as well. I often find filter and map used together.
array.flatMap(v=>{if(!v.active){// Returning an empty array here is equivalent to filtering out the element.return[];}// Returning a single element array with the mapped value keeps the element.return[v.label];});
Exposing an API like this would have to deal with choosing a value that represents "filter this out". Is it false? What if I wanted to map to boolean values?
flatMap's wrapping arrays sidestep this, since it's not the return value but the value's length that differentiates it.
With
flatMap
added withflat
to reduce iterations and allocations, it would be nice to have an accompanyingfilterMap
method as well. I often find filter and map used together.Something like this:
Could be written as:
The text was updated successfully, but these errors were encountered: