I.e., something like:
(defn dowith [f & arglists]
(doseq [args arglists] (apply f args)))
Is there a built-in function like that in Clojure?
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.
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.
As mentioned previously the len function will return the number of elements in a list.
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.
No, there is no built-in function that does that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With