Skip to content

Commit

Permalink
Merge pull request #208 from stuarth/dict-update-with-a-result
Browse files Browse the repository at this point in the history
Dict.update works with a Result
  • Loading branch information
Anton-4 authored Sep 26, 2024
2 parents a987b0b + a28758a commit 423d54d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions examples/BasicDict/BasicDict.roc
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ expect

# We need to account for the case when a key (=fruit) is not in the Dict.
# So we need a function like this:
addFruit : [Present U64, Missing] -> [Present U64, Missing]
addFruit : Result U64 [Missing] -> Result U64 [Missing]
addFruit = \valueTag ->
when valueTag is
# If the fruit is not in the dict (=missing), we set the count to 1
Missing -> Present 1
Err Missing -> Ok 1
# If the fruit is in the dict (=present), we increase the count
Present count -> Present (count + 1)
Ok count -> Ok (count + 1)

Dict.get updatedDict "Apple" == (Ok 4)

Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 423d54d

Please sign in to comment.