Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Swift Functional Programming

You're reading from   Swift Functional Programming Ease the creation, testing, and maintenance of Swift codes

Arrow left icon
Product type Paperback
Published in Apr 2017
Publisher Packt
ISBN-13 9781787284500
Length 316 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dr. Fatih Nayebi Dr. Fatih Nayebi
Author Profile Icon Dr. Fatih Nayebi
Dr. Fatih Nayebi
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Started with Functional Programming in Swift FREE CHAPTER 2. Functions and Closures 3. Types and Type Casting 4. Enumerations and Pattern Matching 5. Generics and Associated Type Protocols 6. Map, Filter, and Reduce 7. Dealing with Optionals 8. Functional Data Structures 9. Importance of Immutability 10. Best of Both Worlds and Combining FP Paradigms with OOP 11. Case Study - Developing an iOS Application with FP and OOP Paradigms

Optional types


In our day-to-day application development, we encounter situations where we expect to receive a value but we do not receive it. For instance, suppose that we have a list of items and we need to search for a particular value in the list. The particular value that we are looking for might not be on the list. Other examples can be calling a web service and receiving a JSON payload without the fields that we are looking for, or querying a database and not receiving the expected values.

What are we going to receive when the value is not there, and how will we handle this absence?

In programming languages such as C, it is possible to create a variable without giving it a value. If we try to use the variable before assigning a value, we would get an undefined value.

In Swift, we can define a variable without giving it a value, but we cannot use it without assigning some value to it. In other words, we need to initialize it before being able to use it. This feature of Swift ensures that...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image