OpenFn / adaptors

The new home for OpenFn adaptors; re-usable connectors for the most common DPGs and DPI building blocks.
GNU General Public License v3.0
7 stars 8 forks source link

common: re-write `map() ` to work like Array.map #499

Open josephjclark opened 7 months ago

josephjclark commented 7 months ago

common currently has a function called map, which so far as I can tell is exactly the same as each (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, where data 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:

That leaves us with a signature like

map(path, callback, options)

it's pretty weird too have options after callback, but also weird to force options.

josephjclark commented 4 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

mtuchi commented 3 months ago

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

aleksa-krolls commented 3 months ago

Noted @mtuchi pls move to Blocked for this week, and we can revisit this at a later date once we hear from @josephjclark