What this book covers
Chapter 1, Getting Started with Functional Programming in Swift, introduces functional programming paradigms by attempting to answer the questions of Why functional programming matters? and What is functional programming? It covers topics such as immutability, stateless programming, pure, first-class, and higher-order functions. Also, this chapter will introduce the Swift programming language basics as they are essential for the rest of the book.
Chapter 2, Functions and Closures, begins with the definition of functions, continues with other related topics, such as function types, and finally concludes with more advanced topics such as first-class functions, higher-order functions, function composition, custom operator definition, closures, function currying, recursion, and memoization.
Chapter 3, Types and Type Casting, takes a look at types in general by introducing different kinds of types such as concrete, abstract, product, and sum. We will cover topics such as value and reference type constants, mixing value and reference types, and copying. Then, we will discuss the characteristics of value types. We will also cover the key differences between value and reference types, and how we should decide which one to use. Finally, we will explore equality, identity, type checking, and casting topics.
Chapter 4, Enumerations and Pattern Matching, explains the enumeration definition and usage. We will cover associated and raw values and being introduced to the concept of algebraic data types. We will explore some examples to cover the sum, product, and recursion types. Also, in this chapter, we will explore patterns such as wildcard, value-binding, identifier, tuple, enumeration case, optional, type casting, and expression, along with related pattern matching examples.
Chapter 5, Generics and Associated Type Protocols, teaches us how to define and use generics. We will also understand the type of problems generics solve. Moving forward, we will explore type constraints, generic data structures, and associated type protocols with examples. We will explore type erasure by an example and finally we will learn how to extend generic types and how to subclass generic classes.
Chapter 6, Map, Filter, and Reduce, introduces the concept of higher-kinded types, Functor, Applicative Functor, and Monad. This chapter covers higher-order functions/methods such as map, flatMap, filter, and reduce in the Swift programming language with examples. The chapter continues by providing implementation of map, filter, flatMap, and flatten in terms of reduce. Then it provides, apply, join, chaining higher-order functions, and zip. Finally, it provides practical examples of higher-order function usage.
Chapter 7, Dealing with Optionals, familiarizes us with different techniques to deal with optionals. We will talk about built-in techniques to deal with optionals, such as optional binding, guard, coalescing, and optional chaining. Then, we will explore functional programming techniques to deal with optionals. Finally, this chapter will cover the error handling with an example.
Chapter 8, Functional Data Structures, introduces the concept of functional data structures and explores examples of data structures implemented in a functional way, such as Semigroup, Monoid, BST, LinkedList, Stack, and LazyList.
Chapter 9, Importance of Immutability, explores the concept of immutability. We will look at its importance and benefits with the help of examples. Then we will consider cases for mutability and go through an example to compare mutability and immutability effects on our code. Finally, we will explore copy constructors and lenses.
Chapter 10, The Best of Both Worlds - Combining FP Paradigms with OOP, covers object- oriented programming principles and paradigms. Then, we will be introduced to protocol- oriented programming. Next, we will have an introduction of functional reactive programming and explore how to mix FP with OOP paradigms.
Chapter 11, Case Study - Developing an iOS Application with the FP and OOP Paradigms, teaches us to develop a Todo backend with Vapor framework and an iOS application, employing the concepts covered in previous chapters. We will use functional programming techniques to parse and map the data, we will use functional reactive programming to reactively manage events in applications. We will also employ protocol-oriented programming and object-oriented programming techniques as well.