Search code examples
elm

Multivariate function composition


Let's consider the following:

f: Int -> Int -> Int -> Int
f a b c = a + b + c

g: Int -> Int
g x = x * 2

now, I'd like to create a composed function like

f(g(a), g(b), g(c))

how to use << and >> operators to achieve that? Is it even possible to compose multivariadic functions?


Solution

  • Multivariadic does not really exist in Elm. Best I can suggest is

    f : Int -> Int -> Int -> Int
    f a b c =
        [ a, b, c ] |> List.map ((<|) g) |> List.sum
    
    
    g : Int -> Int
    g x =
        x * 2
    

    Note that you had an error in the type signature for g