matcher()
Return a function that checks if an object has matching key-value pairs.
Implementation
Args: attrs: The attributes to match Returns: A function that checks if objects match the attributes
Example
obj = {'a': 1, 'b': 2}
matcher({'a': 1, 'b': 2})(obj)
Expected output: True
Source Code
def matcher(attrs: dict) -> Callable:
def match(obj):
return all(obj.get(k) == v for k, v in attrs.items())
return match