Skip to content

Commit

Permalink
Add example and documentation for pattern matching condition
Browse files Browse the repository at this point in the history
  • Loading branch information
fpottbaecker committed Jan 6, 2024
1 parent a68dbb9 commit be79e56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions language.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ Candy supports structural pattern matching using the match operator `%`.

```candy
bar = foo 5 %
[Ok, value] -> ...
[Error, errorValue], core.int.isEven errorValue -> ...
Ok value -> ...
Error errorValue, core.int.isEven errorValue -> ...
_ -> ...
```

Expand Down
10 changes: 10 additions & 0 deletions packages/Examples/match.candy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ifElse, int] = use "Core"

foo value =
needs (int.is value)
ifElse (value | int.isLessThan 5) { Ok value } { Error "NOPE" }

main = foo 2 %
Ok value, value | int.isGreaterThan 5 -> value
Error value -> 10
_ -> 20

0 comments on commit be79e56

Please sign in to comment.