Reputation: 53
I have a method:
def replaceSpecialSymbols(str: String): String = str.collect {
case '/' => '-'
case _ => _
}.toString
Whe I try to build this code, I receive the error message: "error: unbound placeholder parameter case _ => _"
I know that I can use replaceAll. But I want to know what is going on in this case in Scala compiler.
Thank you.
Upvotes: 4
Views: 309
Reputation: 38217
Use case x => x
— problem solved. Also, you can just use map
instead of collect
because it's an exhaustive match.
Or if you only need the first case, just remove that case _ => _
altogether and keep using collect
.
Upvotes: 5