This module is for building let expressions.
Here's a brief example to get you started
Elm.Let.letIn
(\one two ->
Elm.Op.append one two
)
|> Elm.Let.value "one" (Elm.string "Hello")
|> Elm.Let.value "two" (Elm.string "World!")
|> Elm.Let.toExpressionWill translate into
let
one =
"Hello!"
two =
"World"
in
one ++ twoHere's an example destructing a tuple. This code
Elm.Let.letIn
(\( first, second ) ->
Elm.Op.append first second
)
|> Elm.Let.tuple "first" "second" (Elm.tuple (Elm.string "Hello") (Elm.string "World!"))
|> Elm.Let.toExpressionWill generate
let
( first, second ) =
( "Hello", "World!" )
in
first ++ secondAnd extracting fields from a record.
Elm.Let.letIn
(\fields ->
case fields of
[ first, second ] ->
Elm.Op.append first second
_ ->
Elm.unit
)
|> Elm.Let.record [ "first", "second" ]
(Elm.record
[ ( "first", Elm.string "Hello" )
, ( "second", Elm.string "world!" )
]
)
|> Elm.Let.toExpressionWill generate:
let
{ first, second } =
{ first = "Hello", second = "world!" }
in
first ++ secondHere's an example of declaring functions in a let expression:
Elm.Let.letIn
(\myFn ->
myFn (Elm.bool True)
)
|> Elm.Let.fn "myFn"
( "arg", Just Type.bool )
(\arg ->
Elm.ifThen arg
(Elm.string "True")
(Elm.string "False")
)
|> Elm.Let.toExpressionwill generate
let
myFn arg =
if arg then
"True"
else
"False"
in
myFn True