Skip to content

Instantly share code, notes, and snippets.

@tggreene
Created October 2, 2018 13:19
Show Gist options
  • Save tggreene/3de47b4af1da3f3f1728dcf726834a6a to your computer and use it in GitHub Desktop.
Save tggreene/3de47b4af1da3f3f1728dcf726834a6a to your computer and use it in GitHub Desktop.
partial-nth #clojure
(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