Skip to content

Instantly share code, notes, and snippets.

@0atman 0atman/thread.py forked from anonymous/chain.py
Last active Jan 5, 2018

Embed
What would you like to do?
clojure `->`-style functional threading
from functools import reduce
def thread(*args):
"functional thread, inspired by clojure and https://stackoverflow.com/a/17122666/333294"
caller = lambda x, y: y(x)
return reduce(caller, args[1:], args[0])
@0atman

This comment has been minimized.

Copy link
Owner Author

commented Jan 5, 2018

>>> thread(
>>>     [1, 2, 3],
>>>     max,  # 3
>>>     str,  # '3'
>>>     len   # 1
>>> ])
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.