aptuug
Last Updated: November 22, 2017
·
152
· fr0gs
Doggy

Convert variable arguments into list and apply a function to the resulting list [Clojure]

If we receive a variable number of arguments in a function and we want to apply a function with a single list parameter to that variable list of
arguments, there is a simple way to do it using the apply function.

(defn apply_args_to_list [f & args] (apply f (list args)))

So say that we call it with the first function that expects a list/vector:

(apply_args_to_list first 1 2 3 4)
1
Say Thanks
Respond

1 Response
Add your response

28400
42595607ede5ee9c75f4da244128a082

In what circumstance would you use this?

12 months ago ·