The Functional Alternative
summary
Generate 100 random numbers into a file, write a Ruby script that prints index and that many hashes, and then try to group consecutive equal rows imperatively — the first solution accumulates state, hits an off by one bug and misses the final group, and ends up messy but functional. Rework the problem as a pure data transformation (each_with_index, reduce/slice to build groups, then render), which runs, is easier to reason about, and makes the new requirement (group if distance ≤ 1) a one-line change.
AI-written summary · about
chapters (8)
- 0:00Functional programming exercise
- 5:05Imperative Ruby solution
- 15:36Critique of imperative flaws
- 20:42Transforming data functionally
- 31:56Adapting functional solution
- 36:10Readability and maintainability
- 40:27ChatGPT for text processing
- 43:51ChatGPT few-shot demo








