Chapter 11. Lazy computations, continuations, and the beauty of monadic composition

 

This chapter covers

  • Lazy computations
  • Exception handling with Try
  • Monadically composing functions
  • Escaping the pyramid of doom with continuations

In this chapter, you’ll first learn why it’s sometimes desirable to define lazy computations; that is, functions that may or may not be executed. You’ll then see how these functions can be composed with other functions, independently of their execution.

Once you’ve got your feet wet with lazy computations, which are just plain functions, you’ll see how the same techniques can be extended to computations that have some useful effects other than laziness. Namely, you’ll learn how to use the Try delegate to safely run code that may throw an exception, and how to compose several Trys. You’ll then learn how to compose functions that take a callback without ending up in “callback hell.”

What holds all these techniques together is that, in all cases, you’re treating functions as things that have certain specific characteristics, and you can compose them independently of their execution. This requires quite a leap in abstraction, but the result is quite powerful.

The contents of this chapter are challenging, so don’t be discouraged if you don’t get it all on your first reading.

11.1. The virtue of laziness

 
 

11.2. Exception handling with Try

 
 

11.3. Creating a middleware pipeline for DB access

 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage