Refactoring toward a more functional style in F#
summary
Shows refactoring an F# implementation of the Trivia kata from mutable, object-style code into deterministic, testable functional code: mutable arrays/lists are replaced with immutable lists/stacks, mutable state is modeled with records and discriminated unions (sum/product types), side effects are isolated by capturing console output and using a golden‑master test, and imperative loops are rewritten as pure functions and recursion. Uses F# scripts and Visual Studio Code to build a game‑state pipeline for a 4‑pile, 12‑space game, with a golden master preserving behavior when players answer incorrectly about 1 in 10 runs.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 2:46Functional style concepts
- 3:07Trivia kata
- 10:05Business types
- 15:43Mutability reduction
- 25:50Product and sum types
- 27:15Pure function transforms
- 39:02Initial state with sum types
- 41:16Recursion in game logic
- 45:50Sum types benefits
- 47:14Side effects and conclusion
related talks
01h 05mBusting the Func'ing Jargon
53mIntroduction to T(ype)DD with F# and Reactive Web Apps with Fable.io
42mA taste of functional programming with F#
58mFunctional Programming with C#
01h 03mNon-Functional Coding
01h 01mThe Power and Practicalities of Immutability
01h 00mFunctional-first programming with F#
01h 08mThinking Functionally with C#
