Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a typical name for a function like 'map' that operates on a list of argument lists instead of multiple lists of arguments?

(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.

like image 349
jtolle Avatar asked Jan 24 '10 20:01

jtolle


People also ask

Can Map function have more than 2 arguments?

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.

What are necessary arguments to write a map?

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.

What is mapping function in ai?

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.

How do I map a list to another list in Python?

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.


1 Answers

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))))
like image 112
Harold L Avatar answered Sep 28 '22 13:09

Harold L