Skip to content

Instantly share code, notes, and snippets.

@oliyh
Created March 24, 2017 19:58
Show Gist options
  • Save oliyh/e1be174336c079a01bcc12e82e6eaa9d to your computer and use it in GitHub Desktop.
Save oliyh/e1be174336c079a01bcc12e82e6eaa9d to your computer and use it in GitHub Desktop.
comp functions that preserve additional arguments: comp-> and comp->>
(defn comp->>
"Like comp but multiple arguments are passed to all functions like partial, except the last which is threaded like ->>"
[f & fs]
(fn [& args]
(reduce (fn [r f']
(apply f' (conj (into [] (butlast args)) r)))
(apply f args)
fs)))
(defn comp->
"Like comp but multiple arguments are passed to all functions like apply, except the first which is threaded like ->"
[f & fs]
(fn [& args]
(reduce (fn [r f']
(apply f' r (rest args)))
(apply f args)
fs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment