-
-
Save 0atman/cc83e79e00f8943adcc1c475a5077e90 to your computer and use it in GitHub Desktop.
clojure `->`-style functional threading
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 functools import reduce | |
def thread(*args): | |
""" | |
Functional thread ->, inspired by clojure and https://stackoverflow.com/a/17122666/333294 | |
Toy example that only works for functions or airity 1 | |
""" | |
caller = lambda x, y: y(x) | |
return reduce(caller, args[1:], args[0]) |
Author
0atman
commented
Jan 5, 2018
•
A full-featured implementation is https://github.com/kachayev/fn.py#functional-style-for-error-handling
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment