chapter three

3 Functional Programming

 

The chapter covers

  • Distinguishing between Partially Applied Functions (reuse) and Currying (chaining)
  • Using Functors to apply functions to values inside a context
  • Leveraging Applicatives for independent wrapped computations
  • Sequencing dependent operations using Monads

Functional programming is often viewed as a dense academic discipline filled with intimidating jargon. At its core, though, it's a toolkit for two things: composition and safety. By treating functions as values and wrapping data in contexts — like a Maybe that might or might not hold a value, or a list that holds many — we can build complex pipelines that are easier to test, easier to reason about, and that handle errors and edge cases without drowning the code in defensive logic.

This chapter is in two halves. The first looks at two ways of manipulating functions themselves — partial application and currying — which are easy to mix up but solve genuinely different problems. The second half climbs a three-step ladder: functors, applicatives, and monads. Each rung handles a slightly harder problem than the last, and each builds on the one below it. The goal isn't to memorize definitions; it's to see why the ladder exists at all, and what each rung lets you do that the previous one couldn't.

3.1 Partially Applied Functions vs. Currying

3.1.1 Currying

3.1.2 Concluding thoughts

3.2 Functors, Applicatives, and Monads

3.2.1 Functors

3.2.2 Applicatives

3.2.3 Monads

3.2.4 The Limitation of Applicatives

3.2.5 Monads to the Rescue

3.3 Closing thoughts

3.4 Summary