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.

Revisions

  1. emidln revised this gist Jul 13, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rpartial.clj
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    (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 loads arguments from the right
    has the effect of being a partial which preloads arguments from the right
    instead of the left.
    e.g.
  2. emidln revised this gist Jul 13, 2018. No changes.
  3. emidln revised this gist Jul 13, 2018. No changes.
  4. emidln created this gist Jul 13, 2018.
    19 changes: 19 additions & 0 deletions rpartial.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    (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 loads 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])))))