0

I want the common name of a higher order function that applies a list of functions onto a single argument.

In this sense it is a converse of map. map takes a function and a list of arguments and applies that function to the entire list. In Python it might look like this

map = lambda fn, args: [fn(arg) for arg in args]

I'm thinking of the function that does the same but has the alternate argument as a list type

??? = lambda fns, arg: [fn(arg) for fn in fns]

I suspect that this function exists and has a common name. What is it?

MRocklin
  • 55,641
  • 23
  • 163
  • 235

1 Answers1

0

Actually, what you describe is not the converse of map, but just map applied in another way. Consider, e.g.,

map(lambda f: f(2), [lambda x: x + 1, lambda x: x, lambda x: x * x])

which in effect applies three functions (plus 1, identity, and squaring) to the argument 2. So what you wanted is just

alt_map = lambda x, fns: map(lambda f: f(x), fns)

which is still an ordinary map.

chris
  • 4,988
  • 20
  • 36