Protocol Witnesses
summary
Argues that every protocol can be replaced by a plain generic struct holding function fields (a protocol witness), demonstrates this by turning a Combineable protocol into a Combining struct with a two-argument combine field so one can have sum and product witnesses for Int concurrently, and shows a pullback operation that derives strategies (image → layer → view → viewController). Rewrites a snapshot-testing library to witnesses (JSON, PNG, GIF, PDF strategies), ships 1.0 after ~2 years in production and reports much simpler composition and new capabilities.
AI-written summary · about
chapters (35)
- 0:00Intro
- 1:00Overview
- 2:00Protocols are great
- 2:47Protocols have problems
- 5:19Protocols have limitations
- 6:29Two protocols
- 8:00Combined able
- 13:01Combined Approach
- 14:51Explicit Approach
- 15:17Explicit Witnesses
- 15:52Combining Witnesses
- 18:50Zip
- 20:55Combining Functions
- 22:45Snapshot Testing
- 23:40Screenshot Testing
- 26:07Protocol Approach
- 26:30Difficult Protocol
- 27:18Snapshot Protocol
- 27:52Generic Algorithm
- 29:56Generic Format
- 30:33Explicit Snapshot
- 30:48Snapshot Strategies
- 31:12Dump Strategy
- 31:38Snapshot Strategy
- 31:55Snapshot with Curl
- 32:13Image Snapshot
- 33:10View Controller Hierarchy
- 33:35PDFs
- 34:20Animation
- 36:20Pullback
- 37:05Snapshot
- 38:22Back
- 39:01Recap
- 39:41Alternatives
- 40:01Pros Cons
related talks
20mGenerics in protocol extensions
35mProtocols with Associated Types
04mStating the obvious
24mPolymorphism with Protocols
27mGeneric Protocols and Associated Types - Power Tools for Unit Testing
46mGeneric Swift: It Isn't Supposed to Hurt
17mFinally Solving the Expression Problem
23mDeclarative Programming in Swift
