Created
October 2, 2018 13:19
-
-
Save tggreene/3de47b4af1da3f3f1728dcf726834a6a to your computer and use it in GitHub Desktop.
partial-nth #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
(defn partial-nth | |
"Takes a function f and position pos with one fewer than required args and | |
returns a fn that takes one argument which will be applied at pos (where pos | |
is 0 indexed ordinal position)" | |
[f pos & args] | |
(fn [x] | |
(let [[before after] (split-at pos args)] | |
(apply f (concat before [x] after))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment