mdgriffith/elm-codegen/4.1.1

NOTE: the latest version is 6.0.3

Elm.Declare

You may run into situations where you want to generate a function, and then call that generated function somewhere else.

This module will help you do that.

Here's an example, let's define a new function called add42

renderFile =
    let
        add42 =
            Elm.Declare.fn "add42"
                ( "firstInt", Nothing )
                (\firstArgument ->
                    Elm.plus
                        (Elm.int 42)
                        firstArgument
                )
    in
    Elm.file [ "MyFile" ]
        -- add our declaration to our file
        [ add42.declaration


        -- and another place where we call that function!
        , Elm.declaration "mySweetNumber"
            (add42.call (Elm.int 82))
        ]

Depending on your situation, you may want to define a function in one file, but call it from another.

In that case you can do something like this using callFrom:

renderFileList =
    let
        add42 =
            Elm.Declare.fn "add42"
                ( "firstInt", Nothing )
                (\firstArgument ->
                    Elm.plus
                        (Elm.int 42)
                        firstArgument
                )
    in
    [ Elm.file [ "MyFile" ]
        -- add our declaration to our file
        [ add42.declaration
        ]
    , Elm.file [ "MyOtherFile" ]
        -- and call from another file
        [ Elm.declaration "mySweetNumber"
            (add42.callFrom [ "MyFile" ] (Elm.int 82))
        ]
    ]
fn :
String
-> ( String, Maybe Annotation )
-> (Expression -> Expression)
-> { declaration : Declaration
, call : Expression -> Expression
, callFrom : List String -> Expression -> Expression
, value : List String -> Expression
}
fn2 :
String
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> (Expression -> Expression -> Expression)
-> { declaration : Declaration
, call : Expression -> Expression -> Expression
, callFrom : List String -> Expression -> Expression -> Expression
, value : List String -> Expression
}
fn3 :
String
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> (Expression -> Expression -> Expression -> Expression)
-> { declaration : Declaration
, call : Expression -> Expression -> Expression -> Expression
, callFrom :
List String -> Expression -> Expression -> Expression -> Expression
, value : List String -> Expression
}
fn4 :
String
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> (Expression -> Expression -> Expression -> Expression -> Expression)
-> { declaration : Declaration
, call :
Expression -> Expression -> Expression -> Expression -> Expression
, callFrom :
List String
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
, value : List String -> Expression
}
fn5 :
String
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
)
-> { declaration : Declaration
, call :
Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
, callFrom :
List String
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
, value : List String -> Expression
}
fn6 :
String
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( String, Maybe Annotation )
-> ( Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
)
-> { declaration : Declaration
, call :
Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
, callFrom :
List String
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
-> Expression
, value : List String -> Expression
}
String
-> Expression
-> { declaration : Declaration
, value : Expression
, valueFrom : List String -> Expression
}
String
-> List ( String, Maybe Annotation )
-> (List Expression -> Expression)
-> { declaration : Declaration
, call : List Expression -> Expression
, callFrom : List String -> List Expression -> Expression
, value : List String -> Expression
}