-
Notifications
You must be signed in to change notification settings - Fork 165
[1LP][WIPTEST] Add match_items() and first() #8018
base: master
Are you sure you want to change the base?
Conversation
|
||
|
||
def match_items(items, filter): | ||
''' Return only items matching filter dict. ''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double quotes on these docblocks please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making this a BaseCollection classmethod instead of just this standalone method, for clarity during use and ability to call self.match_items(self.all(), self.filters)
|
||
|
||
def first(items): | ||
''' Return the first item in the iterable. ''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should definitely be a BaseCollection method, if its included at all. I'm hesitant to include it because its a single line wrapper that doesn't handle StopIteration to return None, or anything 'special' that would make it valuable beyond the caller just using next() or .pop() themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is intended to be used when single item is expected to appear in some list or generator. So added value is that it handles both same way.
We can discuss adding handling StopIteration and raising some other exception instead, if you think it something we should do.
I've just realized I can be checking we got single and only value. So perhaps I should do that and rename this to singletone
or only
or something like that.
What do you think @mshriver
Purpose or Intent
Add some helper methods for filtering and picking first item.