Created
February 22, 2017 00:30
-
-
Save noisesmith/ad14d0b091626de380ad093780ff9915 to your computer and use it in GitHub Desktop.
r-> like -> but it respects reduced
This file contains hidden or 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
| (defmacro r-> | |
| [x & forms] | |
| (loop [x x, forms forms] | |
| (if forms | |
| (let [form (first forms) | |
| threaded (with-meta `(let [x# ~x] | |
| (if (reduced? x#) | |
| x# | |
| (~(first form) x# ~@(next form)))) | |
| (meta form))] | |
| (recur threaded (next forms))) | |
| `(let [x# ~x] | |
| (if (reduced? x#) | |
| @x# | |
| x#))))) | |
| (comment | |
| => (r-> 1 (+ 2) (+ 3) (reduced) (+ 300)) | |
| 6 | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment