In Chapter 6, Map, Filter, and Reduce we talked about map
and flatMap
functions, and we said that optionals are Monads. In this chapter, we will look at optionals. We need to deal with optionals as some of the functions/methods that we need to call or provide may return some values or none. This chapter explores the concept of optionals and provides different techniques to deal with them.
This chapter will cover the following topics with coding examples:
- Optional types
- Unwrapping optionals
- Optional binding
- Guard
- Coalescing
- Optional chaining
- Optional mapping
- Dealing with optionals functionally
- Using
fmap
andapply
for multiple functional mapping - Error handling