Last Updated: August 01, 2022
·
1.334K
· fr0gs

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

1 Response
Add your response

In what circumstance would you use this?

over 1 year ago ·