Skip to content

Instantly share code, notes, and snippets.

@nitely
Created December 26, 2015 04:55
Show Gist options
  • Save nitely/db822a2d9c6a5257c93c to your computer and use it in GitHub Desktop.
Save nitely/db822a2d9c6a5257c93c to your computer and use it in GitHub Desktop.
Python function composition/pipelining
def compose(*funcs):
"""
Compose N functions into one.\
The returned values for a function\
are the received parameters for the next function
Usage::
def parse(request_line_raw):
parser = compose(
split_request_line,
validate_target,
validate_method,
validate_version,
decode
)
return parser(request_line_raw)
"""
def composer(*args):
for func in funcs:
args = func(*args)
return args
return composer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment