liveBook · Manning

FsToolkit.ErrorHandling

As explained in F# in Action: A Revised Edition of Get Programming with F#

FsToolkit.ErrorHandling is an open-source F# library that provides computation expressions and other helpers for working with options and results.

FsToolkit.ErrorHandling is a free, open-source F# package for working with options and results through computation expressions and related helpers. Its option { } expression makes optional-value workflows read like ordinary sequential code while handling failure propagation automatically. section 9.3

The practical pattern is:

  • Bind each optional value with let!, which unwraps Some values and stops the computation when a value is None. section 9.3
  • Return the final calculation inside the expression, avoiding nested pattern matching and manual option plumbing. section 9.3
  • Use result { } similarly for Ok and Error values; let! unwraps Ok and discards Error values. section 9.3
#r "nuget:FSToolkit.ErrorHandling, 2.13.0"          #1
open FsToolkit.ErrorHandling                        #1
 
let myMaybeData = option {                          #2
    let! numberOne = tryParseNumber "1"             #3
    let! numberTwo = tryParseNumber "2"             #3
    let! numberThree = tryParseNumber "3"           #3
    return calc numberOne numberTwo numberThree     #4
}

A compact runnable example installs the package, opens its namespace, parses three optional numbers, and calculates with their unwrapped values. section 9.3

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains let! failure propagation and contrasts concise expressions with manual pattern matching, but defers library internals.
Examples
Demonstrates parsing three numbers, calculating with optional values, and remodelling customer validation with result { }.
What it assumes
Assumes familiarity with F# options, results, and computation expressions while showing package installation and let! usage.
What you can do after
Apply it via option { } and result { } expressions to write succinct, uniform workflows that propagate failure automatically.
How it connects
Connects computation expressions with options, results, pattern matching, NuGet, and package management.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.