8000 Add example for `case _ of` (#147) · purescript/documentation@8ff88ec · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ff88ec

Browse files
craigdallimorehdgarrood
authored andcommitted
Add example for case _ of (#147)
* Add example for `case _ of` * Added further clarification and equivalent example
1 parent d85c606 commit 8ff88ec

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

language/Syntax.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,23 @@ f x = case x of
434434
Right _ -> "Right"
435435
```
436436

437+
A binding can be avoided by using a single underscore in place of the expression to match on; in this context the underscore represents an _anonymous argument_.
438+
``` purescript
439+
case _ of
440+
0 -> "None"
441+
1 -> "One"
442+
_ -> "Some"
443+
```
444+
445+
This is equivalent to
446+
```purescript
447+
\x -> case x of
448+
0 -> "None"
449+
1 -> "One"
450+
_ -> "Some"
451+
```
452+
453+
437454

438455
## If-Then-Else expressions
439456

0 commit comments

Comments
 (0)
0