You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _sips/sips/2021-06-25-pattern-matching-with-named-fields.md
+15-26Lines changed: 15 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -61,14 +61,8 @@ This SIP doesn't aim to allow pattern where parameters go into the pattern, e.g:
61
61
```scala
62
62
valmap=Map("Berlin"->10, "Paris"->5)
63
63
64
-
map match {
64
+
map match
65
65
caseMap("Paris"-> five) => five
66
-
}
67
-
68
-
4match {
69
-
case n /2=>"double of "+ n.toString
70
-
case _ =>"odd"
71
-
}
72
66
```
73
67
74
68
//TODO: find references where this feature was requested
@@ -81,15 +75,14 @@ Before this was invalid syntax, so this shouldn't affect any existing Scala prog
81
75
82
76
### Mixed usage
83
77
84
-
Mixed patterns are allowed to keep the similarity, but have right now no motivational use case. Maybe those should be allowed:
78
+
Mixed patterns, with positional and named patterns are allowed to keep the similarity.
79
+
But they have no motivational use case. Maybe they should be disallowed.
85
80
86
81
```scala
87
82
caseUser("Anna", city = c) =>// Mixed usage seems wired
88
-
caseUser(_, city = c) =>// Leading underscore are espacially to useless (?)
83
+
caseUser(_, city = c) =>// Leading underscore are espacially useless
89
84
```
90
85
91
-
//TODO: What's with user defined `unapply` on case classes? (Design)
92
-
93
86
## Implementation
94
87
95
88
@@ -114,17 +107,16 @@ case User(
114
107
Without allowing user defined named arguments in pattern matching, the fact that class is a case class becomes part if it's public interface. Changing a case class to a normal class is a backward incompatible change, that library maintainers of to be aware. This is especially worrying since currently libraries where designed without this feature in mind.
0 commit comments