Skip to content

Commit 104f71e

Browse files
authored
Merge pull request documentationjs#48 from purescript/chexxor-doc-case-expressions
Document syntax of case-expressions.
2 parents dec29f5 + 5b18b5e commit 104f71e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

language/Syntax.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,19 @@ Operator sections also work for functions used this way:
410410
fooBy2 = (_ `foo` 2)
411411
```
412412

413+
## Case expressions
414+
415+
The `case` and `of` keywords are used to deconstruct values to create logic based on the value's constructors. You can match on multiple values by delimiting them with `,` in the head and cases.
416+
417+
``` purescript
418+
f :: Maybe Boolean -> Either Boolean Boolean -> String
419+
f a b = case a, b of
420+
Just true, Right true -> "Both true"
421+
Just true, Left _ -> "Just is true"
422+
Nothing, Right true -> "Right is true"
423+
_, _ -> "Both are false"
424+
f (Just true) (Right true)
425+
```
413426

414427
## If-Then-Else expressions
415428

0 commit comments

Comments
 (0)