Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Title Page
Copyright
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Getting Started with Functional Programming in Swift
Why functional programming matters
What is FP?
The Swift programming language
Swift features
Modern syntax
Type safety and type inference
Immutability
Stateless programming
First-class functions
Higher-order functions
Closures
Subscripts
Pattern matching
Generics
Optional chaining
Extensions
Objective-C and Swift bridging headers
Automatic Reference Counting
REPL and Playground
Language basics
Types
Type inference
Type annotation
Type aliases
Type casting
Immutability
Tuples
Optionals
Basic operators
Strings and characters
Immutability
String literals
Empty Strings
Concatenating strings and characters
String interpolation
String comparison
Collections
Control flows
for loops
while loops
The stride functions
if
Switch
Guard
Functions
Closures
The map, filter, and reduce functions
The map function
The filter function
The reduce function
Enumerations
Generics
Classes and structures
Classes versus structures
Choosing between classes and structures
Identity operators
Properties
Property observers
Methods
Subscripts
Inheritance
Initialization
De-initialization
Automatic Reference Counting
Any and AnyObject
Nested types
Protocols
Protocols as types
Extensions
Protocol extensions
Access control
Error handling
Summary
Functions and Closures
What is a function?
Syntax
Best practices in function definition
Calling functions
Defining and using function parameters
Defining and using variadic functions
Returning values from functions
Defining and using nested functions
Pure functions
Function types
First-class functions
Higher-order functions
Function composition
Custom operators
Allowed operators
Custom operator definition
A composed function with custom operator
Closures
Closure syntax
Capturing values
Function currying
Recursion
Tail recursion
Memoization
Summary
Types and Type Casting
Kinds of types
Value versus reference types
Value and reference type constants
Mixing value and reference types
Copying
Copying reference types
Value type characteristics
Behaviour
Isolation
Interchangeability
Testability
Threats
Using value and reference types
Equality versus identity
Equatable and Comparable
Type checking and casting
Summary
Enumerations and Pattern Matching
Defining enumerations
Associated values
Raw values
Nesting and containing enumerations
Algebraic data types
Simple types
Composite types
Composite types with variants
The algebra of data types
Pattern matching
Patterns and pattern matching
The wildcard pattern
The value-binding pattern
The identifier pattern
The tuple pattern
The enumeration case pattern
The optional pattern
Type casting patterns
The expression pattern
Summary
Generics and Associated Type Protocols
What are Generics and what kind of problems do they solve?
Type constraints
The where clauses
Generic data structures
Associated type protocols
Type erasure
Extending Generic types
Subclassing Generic classes
Generics manifesto
Summary
Map, Filter, and Reduce
Higher-kinded types
Functors
Applicative Functors
Monads
The map function
The flatMap method
The filter function
The reduce function
The map function in terms of reduce
The filter function in terms of reduce
The flatMap function in terms of reduce
The flatten function in terms of reduce
The apply function
The join function
Chaining higher-order functions
The zip function
Practical examples
Sum and product of an array
Removing nil values from an array
Removing duplicates in an array
Partitioning an array
Summary
Dealing with Optionals
Optional types
Unwrapping optionals
Force unwrapping
nil checking
Optional binding
Guard
Implicitly-unwrapped optionals
Nil-coalescing
Optional chaining
Dealing with Optionals' functionally
Optional mapping
Multiple optional value mapping
Error handling
try!
try?
Summary
Functional Data Structures
Semigroups
Monoids
Trees
The contains method
Binary Search Trees
The contains method
Size
Elements
Empty
Lists
Empty LinkedList
Cons
Contains
Size
Elements
isEmpty
map, filter, and reduce
Stacks
Lazy lists
Summary
Importance of Immutability
Immutability
Immutable variables
Weak versus strong immutability
Reference types versus value types
Benefits of immutability
Thread safety
Referential transparency
Low coupling
Avoiding temporal coupling
Avoiding identity mutability
Failure atomicity
Parallelization
Exception handling and error management
Caching
State comparison
Compiler optimization
Cases for mutability
An example
Side-effects and unintended consequences
Testability
Copy constructors and lenses
Copy constructors
Lenses
Lens composition
Summary
Best of Both Worlds and Combining FP Paradigms with OOP
OOP paradigms
Objects
Classes
Inheritance
Overriding
Design constraints
Singleness
Static
Visibility
Composite reuse
Issues and alternatives
When to inherit
Polymorphism
Dynamic binding
OOP design principles
SRP
The FP counterpart
OCP
The FP counterpart
LSP
The FP counterpart
ISP
The FP counterpart
DIP
The FP counterpart
DDD
Concepts
Premise
Building blocks
Aggregate
Immutable value objects
Domain events
Intention-revealing interface
Side-effect-free functions
Assertions
Conceptual contours
Closure of operations
Declarative design
POP
POP paradigms
Protocol composition
Protocol extensions
Protocol inheritance
Associated types
Conforming to a protocol
Functional reactive programming
Building blocks of FRP
Events
Signals
Pipes
Signal producers
Observers
Lifetimes
Actions
Properties
Disposables
Schedulers
An example
Mixing OOP and FP
Problems
Granularity mismatch
FP paradigm availability
First-class values
Closures
FP-OOP interrelation tools
FP support
Effects of having FP capabilities in OOP
Idiomatic effects
Code abstraction at a function/method level
Generic iterator operations
Operation compositions and sequence comprehensions
Function partial applications and currying
Architectural effects
Reduction of the number of object/class definitions
Name abstraction at a function/method level
OOP design patterns - a FP perspective
Strategy pattern
Command pattern
Observer pattern
Virtual proxy pattern
Visitor pattern
Summary
Case Study - Developing an iOS Application with FP and OOP Paradigms
Requirements
High-level design
Frontend
Models
Views
ViewController
State
Store
Actions
Manager
Communication
Communication between layers
Third-party libraries/frameworks
Cross-cutting concerns
Error management and exception handling
Tools
Backend
Vapor
Routing
JSON
Request data
SPM
Backend development
Model
Store
Controller
Posting a new Todo item
Getting a list of Todo items
Getting a specific Todo item
Deleting an item and deleting all Todo items
Updating a Todo item
iOS application development
Configuration
Models
Operators
<^> operator
<*> operator
<| operator
<|? operator
<|| operator
Using Argo models
viewModel
Communication
The request protocol
Conforming to the request protocol
WebServiceManager
Creating a Todo item
Listing Todo items
Lenses
States
Store
Actions
Views
ViewControllers
MasterViewController
IBActions
TableView delegates and DataSource
DetailsViewController
Summary
← Prev
Back
Next →
← Prev
Back
Next →