O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with Optionals

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 and apply for multiple functional mapping
  • Error handling

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required