Conditionals
Last updated
viewHi: string -> string
viewHi name =
div
[]
[]
[ if name == "Noah" then text "Hi Noah" else text "I don't know you" ]case value of
somePotentialValue -> someValueToReturnsayHi: string -> string
sayHi name =
case name of
"noah" -> "Hi, Noah!"
"jeremey" -> "Hello, Jeremy!"
default -> "I don't know you"
binaryToString: number -> string
binaryToString binary =
case binary of
0 -> "0"
1 -> "1"
default -> "0"sum: List number -> number
sum numbers =
case numbers of
x :: xs -> x + (sum xs)
default -> 0type Summary =
ValidSummary { pageCount: number, currentPage: number}
| InvalidSummary { reason: string }
parseSummary: List number -> Summary
parseSummary xs =
case xs of
x :: y :: [] -> ValidSummary { pageCount: x, currentPage: y }
x :: [] -> ValidSummary { pageCount: x, currentPage: y }
default -> InvalidSummary { reason: "Too many values" }parseParens: List string -> string
parseParens xs =
case xs of
"(" :: middle :: ")" :: rest -> String.join "" middle
default -> ""
somethingWithAMiddle: string
somethingWithAMiddel =
parseParens [ "(", "hello", ")" ]
testSomethingWithAMiddle: void
testSomethingWithAMiddle =
Test.equals "hello" somethingWithAMiddle
somethingWithoutAMiddle: string
somethingWithoutAMiddel =
parseParens [ "(", "hello" ]
testSomethingWithoutAMiddle: void
testSomethingWithoutAMiddle =
Test.equals "" somethingWithoutAMiddle function sayHi(name: string): string {
if (name === "noah") {
return "Hi, Noah!";
} else {
return "I don't know you";
}
}
const isMe: boolean = name === "noah" ? true: false;function sayHello(name: string): string {
const _res3373707 = name;
switch (_res3373707) {
case "Noah": {
return "Hi Noah";
}
case "James": {
return "Greetings";
}
default: {
return "I don't know you";
}
}
}
const isKnownPerson = (function(): any {
const _res3373707 = name;
switch (_res3373707) {
case "Noah": {
return true;
}
case "James": {
return true;
}
default: {
return false;
}
}
})();