Open josephjclark opened 7 months ago
I guess one question on this one is: should we actually RESERVE the word map
? Does the implementation team use map
in the same way as we do? I think so but I just wonder if there's a semantic gap there
After having a chat with @josephjclark this issue seems to be unimportant and needs more clarity on what's need to be implemented if we think people are going to use this helper function.
@aleksa-krolls I suggest we put a pause until @josephjclark is back online
Noted @mtuchi pls move to Blocked
for this week, and we can revisit this at a later date once we hear from @josephjclark
common currently has a function called
map
, which so far as I can tell is exactly the same aseach
(but is documented wrongly).I think
map
should work like Javascript's native Array.map.Given an array, it will iterate over each item and call a function. The returned value is added to a new array. Once iteration is complete, the new array is written to state.
Unlike
each
, it does not take an operation as a callback function. Just a function. That's because the return value is not treated like state.Like
each
, it should pass a scoped state object, wheredata
is the item under iteration and the rest of your state is normal.At the end,
map
should return the new state object, just like any other operation.It could take options:
filter
is true, returningnull
will remove the item from the array. Default true.statePath
is set, the new array will be written to this path on stateThat leaves us with a signature like
it's pretty weird too have options after callback, but also weird to force options.