underscore icon indicating copy to clipboard operation
underscore copied to clipboard

Deep pluck feature

Open mohsen1 opened this issue 14 years ago • 11 comments

Can underscore pluck have a deep pluck feature to do this:

_([{o:{a:1}},{o:{a:43}},{o:{a:234}},{o:{a:23}}]).pluck("o.a")

mohsen1 avatar Aug 22 '12 19:08 mohsen1

Nope, we don't want to stray into "string programming". Instead, use map, or a more robust syntax like JSONPath.

jashkenas avatar Aug 22 '12 19:08 jashkenas

String programming?

Nested plucking would be highly useful. Why is this feature not implemented and instead developers are forced to reinvent the wheel?

dandv avatar Jul 08 '14 05:07 dandv

grumble grumble

AlexAllocated avatar Aug 05 '15 21:08 AlexAllocated

underscore has a change of being better than lodash.

dandv avatar Aug 05 '15 22:08 dandv

Just found lodash-deep after I complained here. Had no idea lodash actually implemented some of it. Sweet!

And thanks to Underscore for reinforcing our choice to switch to lodash :)

AlexAllocated avatar Aug 05 '15 22:08 AlexAllocated

I made a _.deepPick back then which is less "string programming"

mohsen1 avatar Aug 05 '15 23:08 mohsen1

@chevex: lodash-deep is a 3rd party module, because lodash also refused to implement deepPluck. Maybe there's a reason for this.

dandv avatar Aug 06 '15 01:08 dandv

@dandv Dan please reread the thread you linked to. Lodash has had deep pluck support since v3.7.0.

jdalton avatar Aug 06 '15 02:08 jdalton

That ^

Lol

AlexAllocated avatar Aug 06 '15 05:08 AlexAllocated

@jdalton That is quite funny because I linked to your comment saying

I still think something that walks namespace string, e.g. a.b.c, has a place just not in Lo-Dash core. It would be great to see a mixin or lib that specializes in this kind of API sugar.

before closing the issue (that's when I stopped reading).

Now I see the link in my post goes a few comments down the thread.

Anyway, I'm happy deep plucking is supported in lodash via _.map(collection, 'a.b.c').

dandv avatar Aug 06 '15 06:08 dandv

@dandv

Now I see the link in my post goes a few comments down the thread.

Glad that's all cleared up :)

Deep property support is also available in several other methods.

jdalton avatar Aug 06 '15 06:08 jdalton