Suor / funcy

A fancy and practical functional tools
BSD 3-Clause "New" or "Revised" License
3.38k stars 144 forks source link

feat: allow multiple keys to be passed to pluck #142

Open iloveitaly opened 10 months ago

iloveitaly commented 10 months ago

This would be really helpful for me.

Curious what you think! Can write tests + update docs if you think it's a good idea.

Suor commented 10 months ago

It makes sense. A nice and backwards compatible addition. I will appreciate a full PR.

Suor commented 9 months ago

Thinking a bit more your implementation and func interface itself is not backwards compatible. Passing a tuple as a key already has meaning:

pluck(('a', 'b'), [{('a', 'b'): 42}]) == 42 

So maybe pluck(*keys, mappings) instead.

SirPavlova commented 6 months ago

Only hashable objects can be used as keys, so passing pluck a list of keys wouldn't cause the same ambiguity that passing a tuple of keys does.

And it makes sense to specify multiple keys as a collection, especially a list or set.

Tuples aren't viable due to being valid keys, but they would be fairly conceptually iffy here anyway. A list is a sequential collection containing separate objects, but a tuple is a single object that just happens to have a sequential internal structure. Passing a tuple of keys doesn't really make sense.

Suor commented 6 months ago

The implementation here is converting list to tuple anyway, so not adding anything new.

@SirPavlova you probably need some other behavior