Skip to content

Commit

Permalink
Fix double declaration of classes and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gkepka committed Sep 15, 2024
1 parent 07a0c46 commit 8ec1d34
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions _tour/pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,31 +242,15 @@ You can use variable binding to get type-dependent behavior while simultaneously
{% tabs pattern-matching-variable-binding class=tabs-scala-version %}
{% tab 'Scala 2' for=pattern-matching-variable-binding %}
```scala mdoc
sealed trait Device
case class Phone(model: String) extends Device {
def screenOff = "Turning screen off"
}
case class Computer(model: String) extends Device {
def screenSaverOn = "Turning screen saver on..."
}

def goIdle(device: Device): String = device match {
def goIdleWithModel(device: Device): String = device match {
case p @ Phone(model) => s"$model: ${p.screenOff}"
case c @ Computer(model) => s"$model: ${c.screenSaverOn}"
}
```
{% endtab %}
{% tab 'Scala 3' for=pattern-matching-variable-binding %}
```scala
sealed trait Device
case class Phone(model: String) extends Device:
def screenOff = "Turning screen off"

case class Computer(model: String) extends Device:
def screenSaverOn = "Turning screen saver on..."


def goIdle(device: Device): String = device match
def goIdleWithModel(device: Device): String = device match
case p @ Phone(model) => s"$model: ${p.screenOff}"
case c @ Computer(model) => s"$model: ${c.screenSaverOn}"
```
Expand Down

0 comments on commit 8ec1d34

Please sign in to comment.