Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
idiomatic way to apply a function with various arities
;;say you have something that looks like
(fnx a b)
(fnx a b2)
(fnx a b c)
(fnx a1 b2 c)
(fnx a2 b2 c2 d)
;;my goal is to avoid the repetition of fnx
(for [args [[a b]
[a b2]
[a b c]
[a1 b2 c]
[a2 b2 c2 d]]]
(apply fnx args))
(doall (map (partial apply fnx)
[[a b]
[a b2]
[a b c]
[a1 b2 c]
[a2 b2 c2 d]]))
;;and finally what I call "applies" which is defined simply as
(defn applies
[f & args]
(map (partial apply f)
;;and used like
(applies fnx [a b]
[a b2]
[a b c]
[a1 b2 c]
[a2 b2 c2 d])
;;it could easily be a macro though

This comment has been minimized.

Copy link

@xpe xpe commented Sep 21, 2013

Yes. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment