diff --git a/book/src/language-tour/blocks.md b/book/src/language-tour/blocks.md index 6bfe0563..d4b0d7bc 100644 --- a/book/src/language-tour/blocks.md +++ b/book/src/language-tour/blocks.md @@ -1,36 +1,29 @@ # Blocks - -If statements - -```gleam -if condition { - -} else { - -} -``` - -Case Patterns - -```gleam -when color is { - Green -> "Success." - Blue -> "Warning." - Red -> "Error!" -} -``` - Let bindings with blocks ```gleam -let num = -5 -let absNum = if num>=0 {num} else {-num} +let x = 3 -let message = when color is { - Green -> "Success." - Blue -> "Warning." - Red -> "Error!" +let z = { + let y = 2 + x + y } ``` +A block can be thought of as calling an anonymous function with no arguments. They can be used anywhere a value is. Since everything is secretly a function, the last statement in any block is implicitly its return. + + +Where If with blocks + +```gleam +let name: Option(String) = someFunction() +let suffix = "" +when name is { + Some(s)->{ + let combined = s + suffix + Some(combined) + } + None->None +} +``` \ No newline at end of file diff --git a/book/src/language-tour/matching.md b/book/src/language-tour/matching.md index 4f637a71..8de759ac 100644 --- a/book/src/language-tour/matching.md +++ b/book/src/language-tour/matching.md @@ -1 +1,11 @@ # Matching + +Case Patterns + +```gleam +when color is { + Green -> "Success." + Blue -> "Warning." + Red -> "Error!" +} +``` \ No newline at end of file