Matches style callback should support collections of non-dicts
stevelacey opened this issue · comments
Maybe this is a design decision/limitation of other things already in pydash, but I expected this to work:
users = User.objects.filter(...)
pydash.find(users, dict(first_name="Steve"))
=> None
Like it does in fnc:
users = User.objects.filter(...)
fnc.find(dict(first_name="Steve"), users)
=> <User: Steve>
I see matches styles callback
takes a dict, but it only seems to work on lists of dicts, aka it doesn't match on attributes/properties, like I expected, and as per fnc, it would be great if these had parity.
I don't really need fnc and I'd use pydash instead if this worked, the matches property style
works but isn't a great way to write this, matches styles callback
requires zero explanation to the uninitiated.
Do you have a minimal, self-contained example that demonstrates the behavior? I can then check to see what's happening under the hood to see how feasible it would be to change. Thanks!
Sure thing, you can exercise it with a namedtuple
:
from collections import namedtuple
import pydash
User = namedtuple('User', ['first_name'])
users = [User('Steve')]
pydash.find(users, dict(first_name='Steve'))
=> None
from collections import namedtuple
import fnc
User = namedtuple('User', ['first_name'])
users = [User('Steve')]
fnc.find(dict(first_name='Steve'), users)
=> User(first_name='Steve')
@stevelacey I've pushed a potential fix for this to the develop
branch. Can you install it for your application and let me know if it resolves your issue?
@dgilland yep works perfect 👌🏼
This is released in 5.1.0
: https://pypi.org/project/pydash/5.1.0/