File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -173,28 +173,28 @@ We can also use extractor objects for string pattern matching.
173
173
{% tabs s-interpolator-pattern-matching-2 class=tabs-scala-version %}
174
174
{% tab 'Scala 2' for=s-interpolator-pattern-matching-2 %}
175
175
``` scala
176
- object Int {
176
+ object Age {
177
177
def unapply (s : String ): Option [Int ] = s.toIntOption
178
178
}
179
179
180
180
val input : String = " Alice is 25 years old"
181
181
182
182
val (name, age) = input match {
183
- case s " $name is ${Int (age)} years old " => (name, age)
183
+ case s " $name is ${Age (age)} years old " => (name, age)
184
184
}
185
185
// name: String = Alice
186
186
// age: Int = 25
187
187
```
188
188
{% endtab %}
189
189
{% tab 'Scala 3' for=s-interpolator-pattern-matching-2 %}
190
190
``` scala
191
- object Int :
191
+ object Age :
192
192
def unapply (s : String ): Option [Int ] = s.toIntOption
193
193
194
194
val input : String = " Alice is 25 years old"
195
195
196
196
val (name, age) = input match
197
- case s " $name is ${Int (age)} years old " => (name, age)
197
+ case s " $name is ${Age (age)} years old " => (name, age)
198
198
// name: String = Alice
199
199
// age: Int = 25
200
200
```
You can’t perform that action at this time.
0 commit comments