Swift 3 Functional Programming

Bring the power of Swift functional programming to iOS, Web, macOS, watchOS and tvOS application development and build clean, smart, scalable and reliable applications

Swift 3 Functional Programming

This ebook is included in a Mapt subscription
Dr. Fatih Nayebi

1 customer reviews
Bring the power of Swift functional programming to iOS, Web, macOS, watchOS and tvOS application development and build clean, smart, scalable and reliable applications
$10.00
$44.99
RRP $35.99
RRP $44.99
eBook
Print + eBook
Access every Packt eBook & Video for just $100
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Find Out More
 
Preview in Mapt

Book Details

ISBN 139781785883880
Paperback296 pages

Book Description

This book is based on Swift 3 Developer preview version and aims at simplifying the functional programming (FP) paradigms making it easily usable, by showing you how to solve many of your day-to-day development problems.

Whether you are new to functional programming and Swift or experienced, this book will strengthen the skills you need to design and develop high-quality, scalable, and efficient applications.

The book starts with functional programming concepts, the basics of Swift 3, and essential concepts such as functions, closures, optionals, enumerations, immutability, and generics in detail with coding examples.

Furthermore, this book introduces more advanced topics such as function composition, monads, functors, applicative functors, memoization, lenses, algebraic data types, functional data structures, functional reactive programming (FRP), protocol-oriented programming (POP) and mixing object-oriented programming (OOP) with functional programming (FP) paradigms.

Finally, this book provides a working code example of a front-end application developed with these techniques and its corresponding back-end application developed with Swift.

Table of Contents

Chapter 1: Getting Started with Functional Programming in Swift
Why functional programming matters?
What is functional programming?
The Swift programming language
Summary
Chapter 2: Functions and Closures
What is a function?
The general syntax of functions and methods
Defining and using function parameters
Defining and using variadic functions
Returning values from functions
Pure functions
Function types
Defining and using nested functions
First-class functions
Higher-order functions
Function composition
Closures
Function currying
Recursion
Memoization
Summary
Chapter 3: Types and Type casting
Value versus reference types
Equality versus identity
Equatable and Comparable
Type checking and casting
Summary
Chapter 4: Enumerations and Pattern Matching
Defining enumerations
Associated values
Raw values
Algebraic data types
Pattern matching
Patterns and pattern matching
Summary
Chapter 5: Generics and Associated Type Protocols
What are generics and what kind of problems do they solve?
Type constraints
Generic data structures
Associated type protocols
Extending generic types
Subclassing generic classes
Summary
Chapter 6: Map, Filter, and Reduce
Functor
Applicative Functor
Monad
Map
FlatMap and flatten
Filter
Reduce
Apply
Join
Chaining higher-order functions
Zip
Practical examples
Summary
Chapter 7: Dealing with Optionals
Optional types
Unwrapping optionals
Guard
Implicitly unwrapped optionals
Error handling to avoid optionals
Nil-coalescing
Optional chaining
Dealing with optionals functionally
Summary
Chapter 8: Functional Data Structures
Semigroup
Monoid
Trees
Lists
Stacks
Lazy list
Summary
Chapter 9: Importance of Immutability
Immutability
Immutable variables
Reference types versus value types
The benefits of immutability
Cases for mutability
An example
Copy constructors and lenses
Summary
Chapter 10: The Best of Both Worlds – Combining FP Paradigms with OOP
OOP paradigms
OOP design principles
Protocol-oriented programming (POP)
Functional Reactive Programming (FRP)
Mixing OOP and FP
Summary
Chapter 11: Case Study – Developing an iOS Application with the FP and OOP Paradigms
Requirements
High-level design
Backend development
iOS application development
Summary

What You Will Learn

  • First-class, higher-order, and pure functions
  • Closures and capturing values
  • Custom operators, recursion, and memoization
  • Value and reference types in Swift
  • Enumerations, algebraic data types, patterns, and pattern matching
  • Generics and associated type protocols
  • Higher-order functions such as map, flatMap filter, and reduce
  • Dealing with optionals, fmap, and apply for multiple functional mapping
  • Functional data structures such as Semigroup, Monoid, Binary Search Tree, Linked List, Stack, and Lazy List
  • Immutability, copy constructors, and lenses
  • Combining FP paradigms with OOP, FRP, and POP in your day-to-day development activities
  • Developing a backend application with Swift
  • Developing an iOS application with FP, OOP, FRP, and POP paradigms

Authors

Table of Contents

Chapter 1: Getting Started with Functional Programming in Swift
Why functional programming matters?
What is functional programming?
The Swift programming language
Summary
Chapter 2: Functions and Closures
What is a function?
The general syntax of functions and methods
Defining and using function parameters
Defining and using variadic functions
Returning values from functions
Pure functions
Function types
Defining and using nested functions
First-class functions
Higher-order functions
Function composition
Closures
Function currying
Recursion
Memoization
Summary
Chapter 3: Types and Type casting
Value versus reference types
Equality versus identity
Equatable and Comparable
Type checking and casting
Summary
Chapter 4: Enumerations and Pattern Matching
Defining enumerations
Associated values
Raw values
Algebraic data types
Pattern matching
Patterns and pattern matching
Summary
Chapter 5: Generics and Associated Type Protocols
What are generics and what kind of problems do they solve?
Type constraints
Generic data structures
Associated type protocols
Extending generic types
Subclassing generic classes
Summary
Chapter 6: Map, Filter, and Reduce
Functor
Applicative Functor
Monad
Map
FlatMap and flatten
Filter
Reduce
Apply
Join
Chaining higher-order functions
Zip
Practical examples
Summary
Chapter 7: Dealing with Optionals
Optional types
Unwrapping optionals
Guard
Implicitly unwrapped optionals
Error handling to avoid optionals
Nil-coalescing
Optional chaining
Dealing with optionals functionally
Summary
Chapter 8: Functional Data Structures
Semigroup
Monoid
Trees
Lists
Stacks
Lazy list
Summary
Chapter 9: Importance of Immutability
Immutability
Immutable variables
Reference types versus value types
The benefits of immutability
Cases for mutability
An example
Copy constructors and lenses
Summary
Chapter 10: The Best of Both Worlds – Combining FP Paradigms with OOP
OOP paradigms
OOP design principles
Protocol-oriented programming (POP)
Functional Reactive Programming (FRP)
Mixing OOP and FP
Summary
Chapter 11: Case Study – Developing an iOS Application with the FP and OOP Paradigms
Requirements
High-level design
Backend development
iOS application development
Summary

Book Details

ISBN 139781785883880
Paperback296 pages
Read More
From 1 reviews

Read More Reviews