(apply f args)
(apply f x args)
(apply f x y args)
(apply f x y z args)
(apply f a b c d & args)
Applies fn f to the argument list formed by prepending intervening arguments to args.
Example
Apply a function to a vector of arguments
Apply a function to a list of arguments
Apply a function to multiple collections of different types
(map (partial apply max) [[1 2 3 4] '(-1 0 1 2)])
Source
(defn
apply
"Applies fn f to the argument list formed by prepending intervening arguments to args."
([f args]
(if
(.-cljs$lang$applyTo f)
(let
[fixed-arity
(.-cljs$lang$maxFixedArity f)
bc
(bounded-count (inc fixed-arity) args)]
(if
(<= bc fixed-arity)
(apply-to f bc args)
(.cljs$lang$applyTo f args)))
(apply-to-simple f (seq args))))
([f x args]
(if
(.-cljs$lang$applyTo f)
(let
[arglist
(list* x args)
fixed-arity
(.-cljs$lang$maxFixedArity f)
bc
(inc (bounded-count fixed-arity args))]
(if
(<= bc fixed-arity)
(apply-to f bc arglist)
(.cljs$lang$applyTo f arglist)))
(apply-to-simple f x (seq args))))
([f x y args]
(if
(.-cljs$lang$applyTo f)
(let
[arglist
(list* x y args)
fixed-arity
(.-cljs$lang$maxFixedArity f)
bc
(+ 2 (bounded-count (dec fixed-arity) args))]
(if
(<= bc fixed-arity)
(apply-to f bc arglist)
(.cljs$lang$applyTo f arglist)))
(apply-to-simple f x y (seq args))))
([f x y z args]
(if
(.-cljs$lang$applyTo f)
(let
[arglist
(list* x y z args)
fixed-arity
(.-cljs$lang$maxFixedArity f)
bc
(+ 3 (bounded-count (- fixed-arity 2) args))]
(if
(<= bc fixed-arity)
(apply-to f bc arglist)
(.cljs$lang$applyTo f arglist)))
(apply-to-simple f x y z (seq args))))
([f a b c d & args]
(if
(.-cljs$lang$applyTo f)
(let
[spread-args
(spread args)
arglist
(cons a (cons b (cons c (cons d spread-args))))
fixed-arity
(.-cljs$lang$maxFixedArity f)
bc
(+ 4 (bounded-count (- fixed-arity 3) spread-args))]
(if
(<= bc fixed-arity)
(apply-to f bc arglist)
(.cljs$lang$applyTo f arglist)))
(apply-to-simple f a b c d (spread args)))))