FsToolkit.ErrorHandling.AsyncSeq 6.0.0-beta010

This is a prerelease version of FsToolkit.ErrorHandling.AsyncSeq.
dotnet add package FsToolkit.ErrorHandling.AsyncSeq --version 6.0.0-beta010
                    
NuGet\Install-Package FsToolkit.ErrorHandling.AsyncSeq -Version 6.0.0-beta010
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FsToolkit.ErrorHandling.AsyncSeq" Version="6.0.0-beta010" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FsToolkit.ErrorHandling.AsyncSeq" Version="6.0.0-beta010" />
                    
Directory.Packages.props
<PackageReference Include="FsToolkit.ErrorHandling.AsyncSeq" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FsToolkit.ErrorHandling.AsyncSeq --version 6.0.0-beta010
                    
#r "nuget: FsToolkit.ErrorHandling.AsyncSeq, 6.0.0-beta010"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FsToolkit.ErrorHandling.AsyncSeq@6.0.0-beta010
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FsToolkit.ErrorHandling.AsyncSeq&version=6.0.0-beta010&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FsToolkit.ErrorHandling.AsyncSeq&version=6.0.0-beta010&prerelease
                    
Install as a Cake Tool

FsToolkit.ErrorHandling

FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling.

The library provides utility functions like map, bind, apply, traverse, sequence as well as computation expressions and infix operators to work with Result<'a, 'b>, Result<'a option, 'b>, Async<Result<'a, 'b>>, Async<Result<'a option, 'b>>, and Result<'a, 'b list>.

It was inspired by Chessie and Cvdm.ErrorHandling (the latter has now been merged into FsToolkit.ErrorHandling).

FsToolkit.ErrorHandling targets .NET Standard 2.0, .NET Standard 2.1, .NET 9.0, .NET 10.0, and .NET 11.0, and supports Fable.

Documentation

The documentation is available here.

Further material

Builds

GitHub Actions
GitHub Actions

NuGet

Package name Release Prerelease
FsToolkit.ErrorHandling NuGet NuGet
FsToolkit.ErrorHandling.AsyncSeq NuGet NuGet
FsToolkit.ErrorHandling.IcedTasks NuGet NuGet
FsToolkit.ErrorHandling.Sources NuGet NuGet

Developing locally

Devcontainer

This repository has a devcontainer setup for VSCode. For more information see:

Local Setup

Optional

To test Fable and WebSharper builds locally you will need:

  • Node
    • v18.0.0 or Higher
    • Not required but recommend that you use NVM to easily manage multiple versions of Node
    • Required for Fable-JavaScript and WebSharper
  • Python
    • v3.12.0 or higher
    • Required for Fable-Python
Compiling
> build.cmd <optional buildtarget> // on windows
$ ./build.sh  <optional buildtarget>// on unix

Without specifying a build target, the default target is SourcesTest, which will run tests for all projects on dotnet, pack the projects into nuget packages, and then test the FsToolkit.ErrorHandling.Sources package. For additional notable targets see below.

Build Targets
  • Clean - Will clean all projects bin and obj folders
  • DotnetTest - Will run tests for dotnet projects
  • NpmTest - Will run tests for fable-javascript projects
  • PythonTest - Will run tests for fable-python projects
  • WebSharperTest - Will run the FsToolkit.ErrorHandling.Tests tests under WebSharper in Node.js, with a proxy project that compiles the FsToolkit.ErrorHandling.Sources package
  • RunTests - Will run tests for dotnet, fable-javascript, fable-python, and WebSharper
  • SourcesTest - Will pack the projects and test the FsToolkit.ErrorHandling.Sources package: the full test suite against the package, a consumer build, and the package's MSBuild checks
  • FormatCode - Will run fantomas to format the codebase

This is not an exhaustive list. Additional targets can be found in the ./build/build.fs file.

A motivating example

This example of composing a login flow shows one example of how this library can aid in clear, simple, and powerful error handling, using just a computation expression and a few helper functions. (The library has many more helper functions and computation expressions as well as infix operators; see the documentation for details.)

// Given the following functions:
//   tryGetUser: string -> Async<User option>
//   isPwdValid: string -> User -> bool
//   authorize: User -> Async<Result<unit, AuthError>>
//   createAuthToken: User -> Result<AuthToken, TokenError>

type LoginError = InvalidUser | InvalidPwd | Unauthorized of AuthError | TokenErr of TokenError

let login (username: string) (password: string) : Async<Result<AuthToken, LoginError>> =
  asyncResult {
    // Async.req parses a value using a Req.* function, or yields the specified error if None
    let! user = username |> tryGetUser |> Async.req Req.some InvalidUser

    // Req.filter gives the specified error if isPwdValid returns false
    let! _ = user |> Req.filter (isPwdValid password) InvalidPwd

    // Error value is wrapped/transformed (Unauthorized has signature AuthError -> LoginError)
    do! user |> authorize |> AsyncResult.mapError Unauthorized

    // Same as above, but synchronous, so we use the built-in mapError
    return! user |> createAuthToken |> Result.mapError TokenErr
  }

Sponsor(s)

<a href="https://www.ajira.tech"><img src="./Ajira-logo.png" alt="Ajira Technologies, India" width="200" /></a>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0-beta010 0 11/24/2026
6.0.0-beta009 47 11/20/2026
6.0.0-beta008 44 11/19/2026
6.0.0-beta007 79 11/18/2026
6.0.0-beta006 82 11/17/2026
6.0.0-beta005 72 11/17/2026
6.0.0-beta004 75 11/17/2026
6.0.0-beta003 109 10/12/2026
6.0.0-beta002 103 9/16/2026
6.0.0-beta001 201 6/2/2026
5.2.0 1,691 2/27/2026
5.2.0-beta001 150 2/27/2026
5.1.0 36,252 9/26/2025
5.1.0-beta001 184 9/26/2025
5.0.1 2,688 7/12/2025
5.0.0 392 6/2/2025
5.0.0-beta014 243 6/2/2025
5.0.0-beta013 276 5/29/2025
5.0.0-beta012 771 5/1/2025
5.0.0-beta011 313 3/30/2025
Loading failed

- [Honor ConfigureAwait(false) in the task builders](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/399) Credits @TheAngryByrd
- fix: in `taskResult`, `taskValidation`, `taskOption`, `taskValueOption`, `valueTaskValueOption`, and their `background` variants, a bind (`let!`, `do!`, `use!`, `match!`, `return!`) of a plain awaitable now awaits the awaiter of that awaitable, as `task { }` does. Before, the builder awaited a new task that wrapped the awaitable. Fixes [#398](https://github.com/demystifyfp/FsToolkit.ErrorHandling/issues/398).
- Behavior change: when such an awaitable has `ConfigureAwait(false)` and is not complete, the builder does not request a return to the captured `SynchronizationContext` after the bind. Before, it did. UI code that touches a control after such a bind, including in a `finally` block after `return!`, must remove `ConfigureAwait(false)` or return to the UI thread itself.
- Behavior change: in `let!`, `do!`, `use!`, `match!`, and `return!`, the `GetAwaiter` member of a custom awaitable now runs in the computation expression, as in `task { }`. An `AsyncLocal` value that it sets is now visible to the code after the bind. In `and!`, `GetAwaiter` still runs in a separate task.
- Behavior change: `and!` of a plain awaitable now gets its awaiter after F# evaluates all `and!` operands. Each operand still starts without waiting for an earlier operand to complete, so the operands run at the same time. With more than two operands, F# nests the merges, so the last two operands get their awaiters first: for three operands, the order is 2, 3, 1. Before, each operand got its awaiter, and registered its continuation if it was not complete, before F# evaluated the next operand. If an operand expression throws, the builder does not await the operands before it. Code that observes when `GetAwaiter`, `IsCompleted`, or `OnCompleted` runs can see the difference, for example a custom awaitable or a `SynchronizationContext` that counts its posts.
- `and!` still continues on the captured context, as `and!` in `task { }` does.
- BREAKING (source and binary): the `Source` member for a plain awaitable now returns `PlainAwaitable<_>`, not a task. In `taskResult` and `taskValidation`, it also has one type parameter less. Code that calls this `Source` directly, and compiled quotations of such a call, must change. Extension members that a consumer adds to the builder types and that take the task that this `Source` returned before (a custom `Bind`, `BindReturn`, `ReturnFrom`, or `MergeSources`) no longer apply to plain awaitables. F# then selects the library member, so such code can compile and give a different value.
- The changed members are `inline`. Assemblies that were compiled against an earlier version keep the old behavior until they are compiled again.