Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a function that takes a list of argument lists and applies each list to a given function?

I.e., something like:

(defn dowith [f & arglists]
  (doseq [args arglists] (apply f args)))

Is there a built-in function like that in Clojure?

like image 513
Philip Kamenarsky Avatar asked May 02 '12 19:05

Philip Kamenarsky


People also ask

How do you pass a list of arguments to a function in Python?

In Python, you can unpack list , tuple , dict (dictionary) and pass its elements to function as arguments by adding * to list or tuple and ** to dictionary when calling function.

How do you apply a function to all items in the list?

The best way to apply a function to each element of a list is to use the Python built-in map() function that takes a function and one or more iterables as arguments. It then applies the function to each element of the iterables. An alternate way is to use list comprehension.

Which list function is used to return and element of the list?

As mentioned previously the len function will return the number of elements in a list.


2 Answers

I write things like that moderately often; its just so short that it's not really worth wrapping:

(map #(apply myfun %) list-of-arglists)

I use map most often so i get the results and keep it lazy. of course if you don't want it lazy and don't want the results then doseq is fine also.

like image 107
Arthur Ulfeldt Avatar answered Nov 15 '22 07:11

Arthur Ulfeldt


No, there is no built-in function that does that.

like image 25
sepp2k Avatar answered Nov 15 '22 08:11

sepp2k