小编Sta*_*n L的帖子

Why does providing a partial function to map throw at runtime rather than give a compile error?

Apologies if this is obvious but I am new to scala and I am getting two unexpected behaviors with the following code:

Seq(1, "a", 2, "b") map { 
    case i: Int => i+1
}
Run Code Online (Sandbox Code Playgroud)

1) I would have expected to get back a collection where the strings are unchanged and the numbers are incremented by 1 but instead I get an error.

2) I believe the case i: Int => i + 1 syntax represents a partial function which is …

scala partialfunction

3
推荐指数
1
解决办法
66
查看次数

标签 统计

partialfunction ×1

scala ×1