Last active
July 13, 2018 15:24
-
-
Save emidln/acf3aae6ec6c366fd30b0eaf980c26fc to your computer and use it in GitHub Desktop.
rpartial.clj ((c) bja; licensed under EPL, the same as clojure)
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
(defmacro rpartial | |
"Takes a form leaving a new variadic function which calls the head of form | |
with the variadic arguments and then the arguments passed in as form. This | |
has the effect of being a partial which preloads arguments from the right | |
instead of the left. | |
e.g. | |
((rpartial str \"World\") \"Hello \")" | |
[& [f & xs]] | |
`(f | |
([x#] | |
(~f x# ~@xs)) | |
([x# y#] | |
(~f x# y# ~@xs)) | |
([x# y# z#] | |
(~f x# y# z# ~@xs)) | |
([x# y# z# & more#] | |
(apply ~f x# y# z# (concat more# [~@xs]))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment