DEV Community

Discussion on: What would you call this function?

Collapse
 
nombrekeff profile image
Keff • Edited

Thanks for the extended explanation.

The .toPairs method is really quite similar, the difference is I return an array of objects instead of tuples. I was considering this name, after seeing the lodash method, and the ruby each_pairs it feels like a pretty good name.

Since you are returning a list of objects, what would you call the type of these objects to differentiate them from the existing paradigm of "pairs"/"entries"?

I was thinking about this a bit, I would consider them something like: propertyPathMap, pathValueMap or pathValuePairs, but I feel they don't express it 100%. Maybe it's just a matter of educating the library users, on what this is and what it means.

One other important difference to the methods mentioned above, is that your method is doing this recursively. I have seen the post-fix "Deep" in method names to describe that behaviour.

Yup, I thought about adding the Deep postfix, maybe I will create the non-deep function as well.

(It would actually mean there would be a great deal of type safety from a plain object, in case you plan to provide types for this.)

What do you mean with this? I'm not that experienced with advanced typing.

PD: You are the only one that has realized it's recursive. It might of been a good idea to have explained it in the main Post.

Thanks again!