Skip to content

Commit 28047b8

Browse files
vlullajulienrfSethTisue
authored
Simplify the example used for case objects. (#2172)
Co-authored-by: Julien Richard-Foy <[email protected]> Co-authored-by: Seth Tisue <[email protected]>
1 parent 0356a59 commit 28047b8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

_overviews/scala3-book/domain-modeling-tools.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,14 @@ case class DecreaseVolume(amount: Int) extends Message
685685
case object StopPlaying extends Message
686686
```
687687

688-
Then in other parts of your code you can write methods like this, which use pattern matching to handle the incoming message:
688+
Then in other parts of your code, you can write methods like this, which use pattern matching to handle the incoming message (assuming the methods `playSong`, `changeVolume`, and `stopPlayingSong` are defined somewhere else):
689689

690690
```scala
691-
def handleMessages(msg: Message) = message match
692-
case PlaySong(name) => playSong(name)
693-
case IncreaseVolume(amt) => changeVolume(amt)
694-
case DecreaseVolume(amt) => changeVolume(-amt)
695-
case StopPlaying => stopPlayingMusic
691+
def handleMessages(message: Message): Unit = message match
692+
case PlaySong(name) => playSong(name)
693+
case IncreaseVolume(amount) => changeVolume(amount)
694+
case DecreaseVolume(amount) => changeVolume(-amount)
695+
case StopPlaying => stopPlayingSong()
696696
```
697697
[ref-enums]: {{ site.scala3ref }}/enums/enums.html
698698
[adts]: {% link _overviews/scala3-book/types-adts-gadts.md %}

0 commit comments

Comments
 (0)