|
|
|
|
|
by servbot
2786 days ago
|
|
Here is something from Clojure that stuck with me as particularly elegant: The -> macro. (-> {}
(add-person 'servbot)
add-age
add-info
add-to-db
notify-status-by-email
log-user-addition
)
So the threading operator is exactly what you ask. It inserts the results of the previous expression as the first argument as the first argument as the next expression. Note this still supports situations where an expression can take more than one argument.Additionally, there is the ->> operator which inserts the previous result as the last argument in the next expression and some a library that includes the "magic wand" operator "-<>" ala (-<> {}
(add-person 'servbot)
(add-age 21 <>)
(add-info 'servbot <> 21)
(add-to-db 'my-db-handle 5432 <>)
notify-status-by-email
(log-user-addition 'dev 'email <> 'paint-by-numbers)
)
This particular set of macros seems entirely trivial until you use it, and then it changes your entire perspective of what functions do since your ability to express the computation pipeline changes completely.Edit: Update for formatting. |
|