When to use Option

后端 未结 4 777
长发绾君心
长发绾君心 2020-12-09 08:40

I learn Scala for some time and can\'t clearly understand the usage of Option. It helps me to avoid null checks when I chain functions (according to docs). That\'s clear for

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 09:19

    When it comes to functional programming in Scala, Option is much preferable than null since it is type-safe and plays nice with other constructs in the functional paradigm.

    Especially, you can easily write idiomatic code using high-order functions on Option. This Scala Option Cheat Sheet is a helpful read on the topic.

提交回复
热议问题