After reading all the existing comments I can contribute some more ideas:
The method doesn't only extract path(s), and in lodash there is already a toPairs: it returns "tuples": [[path, value], [path, value]].
Which is very similar (if not identical) to what Object.entries is doing.
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"?
In other languages "entries" are also typed as {key: string, value: any}
which is only one property away from what you have.
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. (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.)
Hope it helps and also curious about some example use cases for this method.
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!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
After reading all the existing comments I can contribute some more ideas:
The method doesn't only extract path(s), and in lodash there is already a toPairs: it returns "tuples":
[[path, value], [path, value]].Which is very similar (if not identical) to what Object.entries is doing.
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"?
In other languages "entries" are also typed as
{key: string, value: any}which is only one property away from what you have.
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. (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.)Hope it helps and also curious about some example use cases for this method.
I might share some use cases here when it's working correctly!
Thanks for the extended explanation.
The
.toPairsmethod 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 rubyeach_pairsit feels like a pretty good name.I was thinking about this a bit, I would consider them something like:
propertyPathMap,pathValueMaporpathValuePairs, 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.Yup, I thought about adding the Deep postfix, maybe I will create the non-deep function as well.
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!