Search code examples
functionelm

Adding the same paramaters to a list of functions in Elm


The title says it all. While I know that with List.map I am able to apply a function to a list of parameters, I would like to know if there is a workaround to send the same parameter to a list of functions.

I have done a bit of research and found nothing for now.


Solution

  • You can just apply each function of the list to the passed param:

    listOfFunctions : List (String -> String)
    listOfFunctions = [(\x -> x ++ "1"), (\x -> x ++ "2"), (\x -> x ++ "3")]
    
    apply : String -> List String
    apply a = List.map (\f -> f a) listOfFunctions