by Xevi · 4y ago · 0 comments
Is it bad to use map?
So if you're using map sensibly, no there's nothing wrong. But I don't like the dogma I read a lot which is "use map always" because it leads to inexperience developers using it in the wrong circumstances.
> Is it bad to use map?
No.
flatMap takes care of a lot of that
For posterity (and forgive me if this JavaScript syntax is inaccurate; I don't write it so much these days)…
xs.map(a => shouldBeSkipped ? a : f(a))Of course if it were assumed they never need anything but the higher level methods: map, reduce, some, every etc. - then they would probably use some or every if they wanted to break.
I suppose filter could maybe be hacked to do it in some cases dependent on implementation, if the implementation determined that it was impossible to ever return true for any of the items remaining in an array that implementation might effectively break the array processing however every way I can think of doing that would be artificial, horrible, and probably full of side effects.
No it doesn’t.
If I only need to do X
And X cannot do Y
Then I do not need to do Y
-----------------------------
If I need to do Y
And X cannot do Y
Then I need to do something other than X
-------------------------
Give your answer of no it doesn't please be so kind as to outline the logical reasoning that you are envisioning?
on edit: added line between logical statements.