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
Written by Esteban
Related protips
1 Response
In what circumstance would you use this?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Clojure
Authors
Related Tags
#clojure
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#