Skip to content

Instantly share code, notes, and snippets.

@emidln
Last active July 13, 2018 15:24
Show Gist options
  • Save emidln/acf3aae6ec6c366fd30b0eaf980c26fc to your computer and use it in GitHub Desktop.
Save emidln/acf3aae6ec6c366fd30b0eaf980c26fc to your computer and use it in GitHub Desktop.
rpartial.clj ((c) bja; licensed under EPL, the same as clojure)
(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