Created
August 21, 2019 04:28
-
-
Save malcolmgreaves/c56032d10124b81e4b62ce6a499989a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import TypeVar, Collection, Callable, Any | |
T = TypeVar("T") | |
def not_in(collection: Collection[T]) -> Callable[[T], bool]: | |
"""Evaluates to a function that tests that an item is _not_ in a collection. | |
Inverse of `x in collection`. | |
""" | |
return lambda x: x not in collection | |
def tuple_fn( | |
function_of_multiple_arguments: Callable[[Any], T] | |
) -> Callable[[tuple], T]: | |
"""Wraps a function that accepts N arguments to a function that accepts a tuple of length N. | |
""" | |
return lambda args: function_of_multiple_arguments(*args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment