Making Life Easier with Computation Expressions

So far we’ve been dealing with straightforward error-handling logic. We’ve been able to chain together Result-generating functions using bind; and for those functions that were not two-track, we’ve been able to make them fit the two-track model using various “adapter” functions.

Sometimes, though, the workflow logic is more complicated. You may need to work within conditional branches, or loops, or work with deeply nested Result-generating functions. In cases like these, F# offers some relief in the form of “computation expressions.” A computation expression is a special kind of expression block that hides the messiness of bind behind the scenes.

It’s easy to create your own computation expressions. ...

Get Domain Modeling Made Functional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.