iteratee()
Return a function based on the type of value.
Implementation
If value is callable, returns it directly. If value is a dict, returns a matcher function. Otherwise, returns an identity function that checks for equality. Args: value: The value to convert to a function Returns: A function based on the value type
Example
obj = {'a': 1, 'b': 2}
iteratee({'a': 1, 'b': 2})(obj)
Expected output: True
Source Code
def iteratee(value: Any) -> Callable:
if callable(value):
return value
elif isinstance(value, dict):
return lambda obj: all(obj.get(k) == v for k, v in value.items())
else:
return lambda obj: obj == value