-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mapObjIndexedToArray #798
Comments
Can you pls demonstrate some examples on some fixtures data and explain the reason why it should return the array ? I'm trying to understand your motivation and see the practicality of such a function. Thank you |
Motivation: what you can do with it is transform: const patient = {
'abbrev@1':{
version:'1.0.9',
resolved:'https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135'
},
'shell-quote@git+https://github.com/srghma/node-shell-quote.git#without_unlicenced_jsonify':{
version:'1.6.0',
resolved:'git+https://github.com/srghma/node-shell-quote.git#0aa381896e0cd7409ead15fd444f225807a61e0a'
},
'@graphile/plugin-supporter@git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git':{
version:'1.6.0',
resolved:'git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git#1234commit'
},
}
const result = mapObjIndexedReturnArray((value, key) => ({ ...value, name: key }), patient)
const expected = [
{
name: 'abbrev@1',
version:'1.0.9',
resolved:'https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135'
},
{
name: 'shell-quote@git+https://github.com/srghma/node-shell-quote.git#without_unlicenced_jsonify',
version:'1.6.0',
resolved:'git+https://github.com/srghma/node-shell-quote.git#0aa381896e0cd7409ead15fd444f225807a61e0a'
},
{
name: '@graphile/plugin-supporter@git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git',
version:'1.6.0',
resolved:'git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git#1234commit'
},
]
expect(result).toEqual(result) pretty useful function I think, I needed it 3 times in my life |
Yeah I see the potential there. We have to be careful with the name though, |
To form a partial isomorphism with const patient = {
'abbrev@1':{
version:'1.0.9',
resolved:'https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135'
},
'shell-quote@git+https://github.com/srghma/node-shell-quote.git#without_unlicenced_jsonify':{
version:'1.6.0',
resolved:'git+https://github.com/srghma/node-shell-quote.git#0aa381896e0cd7409ead15fd444f225807a61e0a'
},
'@graphile/plugin-supporter@git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git':{
version:'1.6.0',
resolved:'git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git#1234commit'
},
}
const result = unzipObjWith((value, key) => [key, { ...value, name: key }]), patient)
const expected = [
[
'abbrev@1',
'shell-quote@git+https://github.com/srghma/node-shell-quote.git#without_unlicenced_jsonify',
'@graphile/plugin-supporter@git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git',
]
[
{
name: 'abbrev@1',
version:'1.0.9',
resolved:'https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135'
},
{
name: 'shell-quote@git+https://github.com/srghma/node-shell-quote.git#without_unlicenced_jsonify',
version:'1.6.0',
resolved:'git+https://github.com/srghma/node-shell-quote.git#0aa381896e0cd7409ead15fd444f225807a61e0a'
},
{
name: '@graphile/plugin-supporter@git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git',
version:'1.6.0',
resolved:'git+https://1234user:[email protected]/git/users/1234user/postgraphile-supporter.git#1234commit'
},
]
]
expect(result).toEqual(result) So you'll need to do |
ok, we can add unzipObjWith too |
found my function in nix (by chance) https://github.com/NixOS/nixpkgs/blob/70732eb4823336bb3234ea399d797c79d8dccdba/lib/attrsets.nix#L229 it's name - mapAttrsToList |
What about calling your function |
Created special issue for unzipObjWith as |
Is your feature request related to a problem? Please describe.
Function maps object properties into array.
Describe the solution you'd like
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: