Skip to content

Instantly share code, notes, and snippets.

@purplejacket
Created April 1, 2015 23:53
Show Gist options
  • Save purplejacket/36de7061061ec9c49734 to your computer and use it in GitHub Desktop.
Save purplejacket/36de7061061ec9c49734 to your computer and use it in GitHub Desktop.
The Clojure apply function
(defn apply
"Applies fn f to the argument list formed by prepending intervening arguments to args."
{:added "1.0"
:static true}
([^clojure.lang.IFn f args]
(. f (applyTo (seq args))))
([^clojure.lang.IFn f x args]
(. f (applyTo (list* x args))))
([^clojure.lang.IFn f x y args]
(. f (applyTo (list* x y args))))
([^clojure.lang.IFn f x y z args]
(. f (applyTo (list* x y z args))))
([^clojure.lang.IFn f a b c d & args]
(. f (applyTo (cons a (cons b (cons c (cons d (spread args)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment