Skip to content

Instantly share code, notes, and snippets.

@malcolmgreaves
Created August 21, 2019 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcolmgreaves/c56032d10124b81e4b62ce6a499989a8 to your computer and use it in GitHub Desktop.
Save malcolmgreaves/c56032d10124b81e4b62ce6a499989a8 to your computer and use it in GitHub Desktop.
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