(I finally posted and accepted an answer to the effect of "no, there isn't, and the question isn't actually that general".)
Consider the Common Lisp function 'mapcar'. It takes a function and some lists as arguments, and calls the function with arguments pulled from the same position in each list.
Do standard libraries typically have a similar function that takes a single list, where each element of the list is a list of arguments for the function? What is a function like that typically called whether "standard" or not? (This isn't meant to be a Lisp question, but it's the only functional language+library I halfway know.)
I guess I'm asking if an operation like (in pseudo-Lisp):
(mapcar (curry #'apply function-to-map) list-of-arg-lists)
already has a name that is common across multiple languages or libraries (in the same way that 'map' and 'reduce' are names for common operations, not just specific library functions).
Thanks.
We can pass multiple iterable arguments to map() function, in that case, the specified function must have that many arguments. The function will be applied to these iterable elements in parallel. With multiple iterable arguments, the map iterator stops when the shortest iterable is exhausted.
The map function has two arguments (1) a function, and (2) an iterable. Applies the function to each element of the iterable and returns a map object. The function can be (1) a normal function, (2) an anonymous function, or (3) a built-in function.
Mapping functions are a group of functions that could be applied successively to one or more lists of elements. The results of applying these functions to a list are placed in a new list and that new list is returned. For example, the mapcar function processes successive elements of one or more lists.
The map() function iterates over all elements in a list (or a tuple), applies a function to each, and returns a new iterator of the new elements. In this syntax, fn is the name of the function that will call on each element of the list. In fact, you can pass any iterable to the map() function, not just a list or tuple.
I nominate map-apply
or maybe mapply
if you want to just use it yourself or in a small group.
(defun map-apply (fn arg-lists)
(mapcar (lambda (arg-list) (apply fn arg-list))
arg-lists))
(map-apply #'+ '((1 2) (3 4 5)))
=>
(3 12)
EDIT Of course yours isn't just pseudo-Lisp if you have curry
:
(defun curry (f &rest values)
(lambda (&rest more-values)
(apply f (append values more-values))))
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