Elm
If
If and else are something different here without curly brackets {}
if "10" == "10" then "Its ten" else "Not ten"
If Not equal has different symbol here,
if "10" /= "11" then "Its ten" else "Not ten"
String Util
- toIntIf you want to parse String to Int , this is the right util. The below method will return True if the String is parsable to Int or else otherwise Generaly String.toInt will returnResult String Int, Which holds the Value / Error. The below method (validateStringToInt) would be the sample to extract the result value
String.toInt "10"`
Ok 10 : Result.Result String Int
validateStringToInt x =
case (String.toInt x) of
Ok value -> True
Err msg -> False
String Contact
Use ++ instead of regular + operator to concat. Every thing value here (Immutable) when doing contact it will give your new valuea = "one " ++ "two" "one two" : String a ++ "end" "one twoend" : String
Tuple
- TupleTuples are simple structure which hold the data in a order to server.(10,11)
Access Tuple
fist element of the typle
fst (10,11)
second element of the tuple
snd (10,11)
Lambda expression
Forward slash for the parameter and -> function body(\x -> x * 2)Below code is for maping list to double listdouble list = List.map (\x -> x * 2) list <function> : List number -> List number double [2,3,4] [4,6,8] : List numberIn Short lambda can be written like for single element , that automaticaly taken as default parameterdouble list = List.map ((*) 2) list
No comments:
Post a Comment