1Obligatory Preamble
- 1.1Why should I read this book?
- 1.2How to read this book
- 1.3Chosen language and optics encodings
- 1.4Your practice environment
- 1.5Following examples
- 1.6About the type signatures
- 1.7About the exercises
2Optics
- 2.1What are optics?
- 2.2Strengths
- 2.3Weaknesses
- 2.4Practical optics at a glance
- 2.5Impractical optics at a glance
3Lenses
- 3.1Introduction to Lenses
- Anatomy
- Exercises – Optic Anatomy
- 3.2Lens actions
- Viewing through lenses
- Setting through a lens
- Exercises - Lens Actions
- 3.3Lenses and records
- Lenses subsume the “accessor” pattern
- Building a lens for a record field
- Exercises - Records Part One
- Getting and setting with a field lens
- Modifying fields with a lens
- Automatically generating field lenses
makeLenses- Exercises - Records Part Two
- 3.4Limitations
- Is it a Lens?
- Is it a Lens? – Answers
- 3.5Lens Laws
- Why do optics have laws?
- The Laws
- Breaking Laws
- Case Study:
_1 - Case Study:
msg - Case Study:
lensProduct - Exercises - Laws
- 3.6Virtual Fields
- What’s a virtual field
- Writing a virtual field
- Breakage-free refactoring
- Exercises – Virtual Fields
- 3.7Data correction and maintaining invariants
- Including correction logic in lenses
- Exercises – Self-Correcting Lenses
4Polymorphic Optics
- 4.1Introduction to polymorphic optics
- Simple vs Polymorphic optics
- 4.2When do we need polymorphic lenses
- Type-changing focuses
- Changing type variables with polymorphic lenses
- Exercises – Polymorphic Lenses
- 4.3Composing Lenses
- How do I update fields in deeply nested records?
- Composing update functions
- Composing Lenses
- How do Lens Types Compose?
- Exercises – Lens Composition
5Operators
- 5.1Lens Operators
- 5.2
viewa.k.a.^. - 5.3
seta.k.a..~ - 5.4Chaining many operations
- 5.5Using
%~a.k.a.over - 5.6Learning Hieroglyphics
- 5.7Modifiers
- 5.8When to use operators vs named actions?
- 5.9Exercises – Operators
6Folds
- 6.1Introduction to Folds
- Focusing all elements of a container
- Decomposing Problems
- Collapsing the Set
- Collecting focuses as a list
- Using lenses as folds
- Composing folds
- Foundational fold combinators
- Exercises – Simple Folds
- 6.2Custom Folds
- Mapping over folds
- Combining multiple folds on the same structure
- Exercises – Custom Folds
- 6.3Fold Actions
- Writing queries with folds
- Queries case study
- Folding with effects
- Combining fold results
- Using ‘view’ on folds
- Customizing monoidal folds
- Exercises – Fold Actions
- 6.4Higher Order Folds
- Taking, Dropping
- Backwards
- TakingWhile, DroppingWhile
- Exercises – Higher Order Folds
- 6.5Filtering folds
- Filtered
- Exercises – Filtering
- 6.6Fold Laws
7Traversals
- 7.1Introduction to Traversals
- How do Traversals fit into the hierarchy?
- A bit of Nostalgia
- From fold to traversal
- 7.2Traversal Combinators
- Traversing each element of a container
- More Combinators
- Traversing multiple paths at once
- Focusing a specific traversal element
- 7.3Traversal Composition
- Exercises – Simple Traversals
- 7.4Traversal Actions
- A Primer on Traversable
- Traverse on Traversals
- Infix traverseOf
- Using Traversals directly
- Exercises – Traversal Actions
- 7.5Custom traversals
- Optics look like
traverse - Our first custom traversal
- Traversals with custom logic
- Case Study: Transaction Traversal
- Exercises – Custom Traversals
- 7.6Traversal Laws
- Law One: Respect Purity
- Law Two: Consistent Focuses
- Good Traversal Bad Traversal
- Exercises – Traversal Laws
- 7.7Advanced manipulation
- partsOf
- Polymorphic partsOf
- partsOf and other data structures
- Exercises – partsOf
8Indexable Structures
- 8.1What’s an “indexable” structure?
- 8.2Accessing and updating values with ‘Ixed’
- The
IxedClass - Accessing and setting values with
ix - Indexed Structures
- Indexing monomorphic types
- Indexing stranger structures
- 8.3Inserting & Deleting with ‘At’
- Map-like structures
- Manipulating Sets
- Exercises – Indexable Structures
- 8.4Custom Indexed Data Structures
- Custom Ixed: Cyclical indexing
- Custom At: Address indexing
- Exercises – Custom Indexed Structures
- 8.5Handling missing values
- Checking whether updates succeed
- Fallbacks with ‘failing’
- Default elements
- Checking fold success/failure
- Exercises – Missing Values
9Prisms
- 9.1Introduction to Prisms
- How do Prisms fit into the hierarchy?
- Simple Pattern-Matching Prisms
- Checking pattern matches with prisms
- Generating prisms with makePrisms
- Embedding values with prisms
- Other types of patterns
- Exercises – Prisms
- 9.2Writing Custom Prisms
- Rebuilding
_Justand_Nothing - Matching String Prefixes
- Cracking the coding interview: Prisms style!
- Exercises – Custom Prisms
- 9.3Laws
- Law One: Review-Preview
- Law Two: Prism Complement
- Law Three: Pass-through Reversion
- Summary
- Exercises – Prism Laws
- 9.4Case Study: Simple Server
- Path prefix matching
- Altering sub-sets of functions
- Matching on HTTP Verb
10Isos
- 10.1Introduction to Isos
- How do Isos fit into the hierarchy?
- There and back again
- 10.2Building Isos
- 10.3Flipping isos with
from - 10.4Modification under isomorphism
- 10.5Varieties of isomorphisms
- Composing isos
- Exercises – Intro to Isos
- 10.6Projecting Isos
- Exercises – Projected Isos
- 10.7Isos and newtypes
- Coercing with isos
- Newtype wrapper isos
- 10.8Laws
- The one and only law: Reversibility
- Exercises – Iso Laws
11Indexed Optics
- 11.1What are indexed optics?
- 11.2Index Composition
- Custom index composition
- Exercises – Indexed Optics
- 11.3Filtering by index
- Exercises – Index Filters
- 11.4Custom indexed optics
- Custom IndexedFolds
- Custom IndexedTraversals
- Index helpers
- Exercises – Custom Indexed Optics
- 11.5Index-preserving optics
12Dealing with Type Errors
- 12.1Interpreting expanded optics types
- 12.2Type Error Arena
- First Foe: Level 1 Lenslion
- Level 2 Tuplicant
- Level 3 Settersiren
- Level 4 Composicore
- Level 5 Foldasaurus
- Level 6 Higher Order Beast
- Level 7 Traversacula
13Optics and Monads
- 13.1Reader Monad and View
- 13.2State Monad Combinators
- 13.3Magnify & Zoom
14Classy Lenses
- 14.1What are classy lenses and when do I need them?
- No duplicate record fields
- Separating logic and minimizing global knowledge
- Granular dependencies with
makeFields - Field requirements compose
- 14.2
makeFieldsvsmakeClassy
15JSON
- 15.1Introspecting JSON
- 15.2Diving deeper into JSON structures
- Tracking down mistakes
- 15.3Traversing into multiple JSON substructures
- Traversing Arrays
- Traversing Objects
- 15.4Filtering JSON Queries
- 15.5Serializing & Deserializing within an optics path
- 15.6Exercises: Kubernetes API
- BONUS Questions
16Uniplate - Manipulating recursive data
- 16.1A Brief History
- 16.2Control.Lens.Plated
- Children
- Rewrite
- Universe
- Transform
- Deep
- 16.3Overriding
plate - 16.4The magic of
biplate - 16.5Exercises – Uniplate
17generic-lens
- 17.1Generic Lenses
- Record Fields
- Positional Lenses
- Typed Lenses
- Altogether Now
- Subtype Lenses
- 17.2Generic Traversals
- Types Traversal
- Parameter Traversals
- 17.3Generic Prisms
- Constructor Prisms
- Typed Prisms
- 17.4Exercises – Generic Lens
18Appendices
- 18.1Optic Composition Table
- 18.2Optic Compatibility Chart
- 18.3Operator Cheat Sheet
- Legend for Getters
- Legend for Setters/Modifiers
- 18.4Optic Ingredients
19Answers to Exercises
- 19.1Optic Anatomy
- 19.2Lens Actions
- 19.3Records Part One
- 19.4Records Part Two
- Laws
- 19.5Virtual Fields
- 19.6Self-Correcting Lenses
- 19.7Polymorphic Lenses
- 19.8Lens Composition
- 19.9Operators
- 19.10Simple Folds
- 19.11Writing Custom Folds
- 19.12Querying Using Folds
- 19.13Higher Order Folds
- 19.14Filtering
- 19.15Simple Traversals
- 19.16Traversal Actions
- 19.17Custom Traversals
- 19.18Traversal Laws
- 19.19partsOf
- 19.20Indexable Structures
- 19.21Custom Indexed Structures
- 19.22Missing Values
- 19.23Prisms
- 19.24Custom Prisms
- 19.25Prism Laws
- 19.26Intro to Isos
- 19.27Projected Isos
- 19.28Iso Laws
- 19.29Indexed Optics
- 19.30Index Filters
- 19.31Custom Indexed Optics
- 19.32Type Errors
- First Foe: Level 1 Lenslion
- Level 2 Tuplicant
- Level 3 Settersiren
- Level 4 Composicore
- Level 5 Foldasaurus
- Level 6 Foldasaurus
- Level 7 Traversacula
- 19.33Kubernetes API
- BONUS Questions
- 19.34Uniplate
- 19.35Generic Lens
20Thanks
- 20.1Patreon Supporters
- 20.2Book Cover
