Quantcast
Viewing latest article 10
Browse Latest Browse All 10

Scala: How to use higher-order functions with Option (instead of match expressions)

Scala: How to use higher-order functions with Option (instead of match expressions)

Table of Contents1 - Sample data2 - From match expressions to higher-order functions3 - Notes4 - Resources5 - Comments

I originally wrote a long introduction to this article about Scala Options, but I decided to keep that introduction for a future second article in this series. For this article I’ll just say:

  • idiomatic Scala code involves never using null values
  • because you never use nulls, it’s important for you to become an expert at using Option, Some, and None
  • initially you may want to use match expressions to handle Option values
  • as you become more proficient with Scala and Options, you’ll find that match expressions tend to be verbose
  • becoming proficient with higher-order functions (HOFs) like map, filter, fold, and many others are the cure for that verbosity

Viewing latest article 10
Browse Latest Browse All 10

Trending Articles