Skip to content

Instantly share code, notes, and snippets.

@L3viathan
Created October 8, 2019 11:08
Show Gist options
  • Select an option

  • Save L3viathan/2f8d8c653b0adfa756a2ea54cb41b7e8 to your computer and use it in GitHub Desktop.

Select an option

Save L3viathan/2f8d8c653b0adfa756a2ea54cb41b7e8 to your computer and use it in GitHub Desktop.
Composable functions
from functools import wraps
def composable(f1):
@wraps(f1)
def wrapper(*args, **kwargs):
if not kwargs and len(args) == 1 and callable(args[0]):
f2 = args[0]
@wraps(f2)
def composed(*a, **k):
return f1(f2(*a, **k))
return composable(composed)
else:
return f1(*args, **kwargs)
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment