Skip to content

Instantly share code, notes, and snippets.

# A quick proof-of-concept. There is some room for improvement.
# Note also that Clojure's macros have no loss of performance compared to writing their expansion (i.e. nested calls) in the first place.
# This, on the other hand, creates a new object per nesting. Python is very flexible, but it's not fast.
class Thead:
"""
Thread-Head class. Like Clojure's -> (thread-first) macro.
>>> import operator as op
>>> Thead(5)(op.sub, 3)(op.mul, 10).result
20