Created
March 24, 2017 19:58
-
-
Save oliyh/e1be174336c079a01bcc12e82e6eaa9d to your computer and use it in GitHub Desktop.
comp functions that preserve additional arguments: comp-> and comp->>
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
(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