Created
December 26, 2015 04:55
-
-
Save nitely/db822a2d9c6a5257c93c to your computer and use it in GitHub Desktop.
Python function composition/pipelining
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
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