Skip to content

Commit

Permalink
Merge pull request #6811 from roc-lang/tutorial-fix-capitalized
Browse files Browse the repository at this point in the history
isCapitalized > startsWith
  • Loading branch information
Anton-4 authored Jun 15, 2024
2 parents 5d09479 + cb5782b commit 41ea2bf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions www/content/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ We can use tags with payloads to make a list that contains a mixture of differen
List.map [StrElem "A", StrElem "b", NumElem 1, StrElem "c", NumElem -3] \elem ->
when elem is
NumElem num -> Num.isNegative num
StrElem str -> Str.isCapitalized str
StrElem str -> Str.startsWith str "A"
# returns [Bool.true, Bool.false, Bool.false, Bool.false, Bool.true]
```

Expand All @@ -708,7 +708,7 @@ Compare this with the example from earlier, which caused a compile-time error:
List.map ["A", "B", "C", 1, 2, 3] Num.isNegative
```

The version that uses tags works because we aren't trying to call `Num.isNegative` on each element. Instead, we're using a `when` to tell when we've got a string or a number, and then calling either `Num.isNegative` or `Str.isCapitalized` depending on which type we have.
The version that uses tags works because we aren't trying to call `Num.isNegative` on each element. Instead, we're using a `when` to tell when we've got a string or a number, and then calling either `Num.isNegative` or `Str.startsWith` depending on which type we have.

We could take this as far as we like, adding more different tags (e.g. `BoolElem Bool.true`) and then adding more branches to the `when` to handle them appropriately.

Expand Down

0 comments on commit 41ea2bf

Please sign in to comment.