Overview
Swift has built-in features that make it very suitable for functional programming (FP) such as high-order functions, value semantics, and protocol-oriented programming. Also, optional types and collections include functional combinators such as map and flatMap to transform and chain computations in a functional way. However, it still lacks abstractions and data types to enable full-fledged FP in the language. Bow is a Swift library that aims to cover that gap.
In this course, we will introduce what is Functional Programming and how Swift can be used with Bow to write code in a more functional style.
Prerequisites
- Experience with Swift.
- A computer with macOS and Xcode.
What you'll learn
Introduction to Functional Programming
- What is Functional Programming
- Swift features for Functional Programming: high-order functions, value types, protocols, optionals, functional combinators.
- Referential Transparency.
- The Substitution Model
Domain modeling with Algebraic Data Types
- Product types: structs, tuples, and classes.
- Coproduct types: enumerations.
Basic Error Handling and Data validation
- Types for error handling: Option, Try, Either, Validated.
- Fail fast and error accumulation strategies for error handling.
Working with Immutable Data with Optics
- Focusing on deeply nested data with Lens, Prism, and Optional
- Composition of optics.
Higher-Kinded Types
- What are Higher-Kinded Types?
- Introduction to polymorphic programs
- Polymorphic functions
- Swift support of HKTs and simulation of HKTs with Bow.
Programming with the core functional type classes
- Modeling Generic Behaviors with Type Classes
- Transforming data with Functor
- Independent computations with Applicative
- Dependent Computations with Monad
- Folding structures into summary values with Foldable
- Traversing nested effects
- Lawful and Lawless instances
Working with Effects
- Dependency Injection alternative with Reader, Kleisli, Extension Functions
- Removing Callback-Hell and nested lambdas
- The rise of Tagless Final
- Suspending side effects for deferred evaluation
- Safe resource acquisition and release
- Integrating with third-party sync and async libraries: RxSwift, BrightFutures
- Testing Effectful Tagless Final programs
Polymorphic Error Handling
- Modeling and raising errors
- Fail Fast and Error Accumulating strategies with ApplicativeError and MonadError