Scala Option: map vs Pattern Matching

后端 未结 3 1307
耶瑟儿~
耶瑟儿~ 2020-12-29 09:35

While dealing with Option in Scala what are the things I should be considering to decide whether to map or patten match? For example, if I have Option[MyC

3条回答
  •  醉梦人生
    2020-12-29 10:14

    Pattern matching is :

    • slightly more efficient
    • not anal about subtypes (in this case @rarry had to add a type hint)
    • easier to read
    • endorsed by Martin Oderksy: https://stackoverflow.com/a/5332657/578101

提交回复
热议问题