An Intuition for List Folds
summary
Defines a cons list as nil or cons and gives precise rules: left fold is a loop used for sum, product, length, reverse (linear time by flipping cons), and fails on infinite lists; right fold replaces constructors so it implements map, append, flatten, filter, headOr and can work on infinite lists when the replacing function is lazy. Shows Haskell code, warns JVM foldr causes StackOverflow for large lists, and demonstrates sequence via foldr with lift-to-cons and return.
AI-written summary · about
chapters (8)
- 0:00Start
- 12:03How Do You Reverse a List
- 21:01Appending to Lists
- 23:17Mapping a Function on a List
- 26:33Function Composition
- 27:22Flattening a List of Lists
- 29:50Favorite Functions
- 45:31Length Function
related talks
38mRefactoring Recursion
56mAn introduction to recursion schemes
01h 05mBusting the Func'ing Jargon
32mRecursion schemes with Higherkindness
31mlazy-seq – a historic view and why it is misunderstood
05mBeautiful Folds
01h 03mIntro to FP in Scala: Exploring a Toolbox for Solving Problems - Part 4 of 6
23mFunctor Zoo
