I understand that functions in Scheme/Racket like map, foldr, and filter, can do wonderful things like apply a function to a list of elements.
Is it possible to apply a list of functions to a single element?
I would like to generate the values produced by each of the functions, then find their maximum. Thank you.
For the first part, this procedure will apply a list of functions to a single argument, assuming that all the functions receive only one argument. A list with the results is returned
For the second part, finding the maximum in the list is simple enough. For example, if the element is
2
and the list of functions is(list sin cos sqr sqrt)
:EDIT :
Here's another possible solution, without using
apply
and in a single procedure:Use it like this:
Another clever way to apply one function after another is to fold with compose like so: