FsToolkit.ErrorHandling.AsyncSeq 6.0.0-beta005

This is a prerelease version of FsToolkit.ErrorHandling.AsyncSeq.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package FsToolkit.ErrorHandling.AsyncSeq --version 6.0.0-beta005
                    
NuGet\Install-Package FsToolkit.ErrorHandling.AsyncSeq -Version 6.0.0-beta005
                    
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-beta005" />
                    
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-beta005" />
                    
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-beta005
                    
#r "nuget: FsToolkit.ErrorHandling.AsyncSeq, 6.0.0-beta005"
                    
#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-beta005
                    
#: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-beta005&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FsToolkit.ErrorHandling.AsyncSeq&version=6.0.0-beta005&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 Standard2.1 and supports Fable.

Documentation

The documentation is available here.

Further material

Builds

GitHub Actions
GitHub Actions
Build History

NuGet

Package name Release Prelease
FsToolkit.ErrorHandling NuGet NuGet
FsToolkit.ErrorHandling.TaskResult NuGet NuGet
FsToolkit.ErrorHandling.JobResult NuGet NuGet
FsToolkit.ErrorHandling.AsyncSeq NuGet NuGet
FsToolkit.ErrorHandling.IcedTasks NuGet NuGet

Developing locally

Devcontainer

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

Local Setup

Optional

To test fable 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
  • Python
    • v3.10.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 DotnetPack, which will run tests for all projects on dotnet and then pack the projects into nuget packages. 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
  • RunTests - Will run tests for dotnet, fable-javascript and fable-python projects
  • 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-beta007 0 11/18/2026
6.0.0-beta006 0 11/17/2026
6.0.0-beta005 0 11/17/2026
6.0.0-beta004 0 11/17/2026
6.0.0-beta003 104 10/12/2026
6.0.0-beta002 100 9/16/2026
6.0.0-beta001 193 6/2/2026
5.2.0 1,680 2/27/2026
5.2.0-beta001 148 2/27/2026
5.1.0 35,836 9/26/2025
5.1.0-beta001 182 9/26/2025
5.0.1 2,661 7/12/2025
5.0.0 388 6/2/2025
5.0.0-beta014 237 6/2/2025
5.0.0-beta013 272 5/29/2025
5.0.0-beta012 769 5/1/2025
5.0.0-beta011 311 3/30/2025
5.0.0-beta010 234 3/21/2025
5.0.0-beta009 824 3/5/2025
5.0.0-beta008 226 3/2/2025
Loading failed

- [`Async.Await`, `Async.StartTaskImmediate`, `Task.startAsyncImmediate`, `Async`+`Task`+`ValueTask` shims and related obsoletions](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/373) Credits @bartelink
- feat(Async, Task, ValueTask): `result`. Replaces `singleton`; aligned with FSharp.Core >= 11 naming.
- BREAKING(Task)!: `catch` returns `Task<Result<_,_>>` (was `Task<Choice<_,_>>`) to match FSharp.Core >= 11.
- NOTE BEHAVIOR CHANGE(Task): `map` on an already completed task runs the mapper at once. If the mapper throws `OperationCanceledException`, the result is now `Faulted` (was `Canceled`), as in FSharp.Core >= 11. A task that is still running gives `Canceled` as before.
- BREAKING(Async, Task, Option)!: Add `RequiresExplicitTypeArguments` to `ignore` align with FSharp.Core Task/Async naming.
- feat: `net11.0` target, which forwards the `Async` and `Task` shims to FSharp.Core 11. FSharp.Core minimum: `netstandard2.0`, `netstandard2.1`, `net6.0` 6.0.4, `net9.0` 9.0.300, `net10.0` 10.0.100, `net11.0` 11.0.101.
- (net10 and lower TFMs) feat(Async, Task, ValueTask): Shims of `Async.Await`, `Async.StartTaskImmediate`, `Task.startAsyncImmediate` and related functions to align with FSharp.Core >= 11.0.0.
- The `ValueTask` overloads, the `ValueTask` module, and `Task.ofValueTask` are also on `netstandard2.0`, through `Microsoft.Bcl.AsyncInterfaces`. FSharp.Core 11 has them only on `netstandard2.1` and later.
- NOTE KNOWN DIFFERENCE(Task): with an already canceled token, `sequential` and `sequentialDo` give `Canceled` and call no factory. On net11, FSharp.Core 11.0.101 calls the factories, because it does not contain dotnet/fsharp#20695. [#384](https://github.com/demystifyfp/FsToolkit.ErrorHandling/issues/384) tracks the FSharp.Core release with the fix.
- (all TFMs) remove(`Async`): functions shadowing FSharp.Core equivalents: `map`, `bind`, `ignore`
- Moved to `FsToolkit.ErrorHandling.FSharpCore11AsyncShims.Async`, which is AutoOpen below net11 and on Fable. On net11, FSharp.Core supplies them.
- (all TFMs) remove(`Task`): functions shadowing FSharp.Core equivalents: `map`, `bind`, `ignore`, `catch`
- Moved to `FsToolkit.ErrorHandling.FSharpCore11TaskShims.Task`, which is AutoOpen below net11. On net11, FSharp.Core supplies them.
- (all TFMs) remove(`Result`): functions shadowing FSharp.Core equivalents: `map`, `mapError`, `bind`, `isOk`, `isError`, `defaultWith`, `defaultValue`
- Moved to `FsToolkit.ErrorHandling.FSharpCore11ResultShims.Result`, which is AutoOpen below net9 and on Fable. On net9 and later, FSharp.Core supplies them.
- These moves keep source compatibility through `open FsToolkit.ErrorHandling`. They are binary breaks on all TFMs.
- [`Async.Await` and `catch`/`catchWith` consistency](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/373) Credits @bartelink
- feat(AsyncResult, JobResult, TaskResult): `catchWith`.
- Same signature as `catch` but aligning with FSharp.Core naming and semantics.
- NOTE KEY BEHAVIOR: `Task.catchWith` does NOT trap `OperationCanceledException`/`TaskCanceledException` (the outgoing `catch` and `Task.ofCatchTask` functions did, the incoming `Task.catch` and `Task.catchWith` functions do not).
- NOTE In contrast, `JobResult.catchWith` _can_ yield `Error TaskCanceledException`/`OperationCanceledException` if the underlying computation is canceled. This is consistent with the `Job.catch` semantics.
- NOTE In contrast, `Async.catchWith` **at present** _can_ yield `Error TaskCanceledException`/`OperationCanceledException` if the underlying computation is canceled, but this is consistent with the incoming `Async.catch`/`Async.catchWith` semantics as they presently stand.
- BREAKING(AsyncOption, AsyncResult, AsyncResultOption, AsyncValidation, CancellableTaskResult, CancellableTaskValidation, CancellableValueTaskOption, ParallelAsyncResult, ParallelAsyncValidation)!:
- Internal usage of `AwaitTask` switches to `Await`
- NOTE BEHAVIOR CHANGE: exceptions surfaced in calling code are no longer egregiously wrapped in `AggregateException`, i.e. you can now `try ... with` targeting the actual exception type to handle exceptions from the awaited Task. [#154](https://github.com/demystifyfp/FsToolkit.ErrorHandling/issues/154).
- Renames:
- OBSOLETE(Async, Task, Job): `singleton`
- -> `result`.
- OBSOLETE(CancellableTaskResult, CancellableTaskValidation, CancellableValueTaskResult): `singleton`
- -> `ok`.
- Removals:
- remove(`Option`)!: functions shadowing FSharp.Core equivalents: `map`, `map2`, `map3`, `bind`
- Present in all supported FSharp.Core versions and Fable, so no reason for them to be in the library.
- OBSOLETE(AsyncResult): `ofAsync`
- -> `Async.map Ok`
- -> CONSIDER `Async.catch`
- NOTE semantics did not match those of `TaskResult.ofAsync`
- OBSOLETE(JobResult): `ofAsync`
- -> `JobResult.fromAsync`
- -> CONSIDER `Job.map Ok`
- NOTE semantics did not match those of `AsyncResult.ofAsync`
- OBSOLETE(TaskResult): `ofAsync`
- -> `Task.startAsyncImmediate ct >> Task.catch`
- OR (if no `CancellationToken` available) -> `Async.StartImmediateAsTask >> Task.catch`
- NOTE semantics did not match those of `AsyncResult.ofAsync`
- NOTE semantics did not cover flowing cancellation
- OBSOLETE(AsyncResult): `ofTask`
- -> `Async.Await >> Async.catch`.
- NOTE semantics did not match those of `TaskResult.ofTask`
- OBSOLETE(TaskResult): `ofTask`
- -> `Task.map Ok`
- -> CONSIDER `Task.catch`
- NOTE semantics did not match those of `AsyncResult.ofTask`
- OBSOLETE(Async): `AwaitCancellableTaskOption`, `AwaitCancellableTaskResult`, `AwaitCancellableTaskValidation`, `AwaitCancellableValueTaskOption`
- -> `Async.StartTaskImmediate` has overloads supporting `Task` and `ValueTask`, and flows cancellation correctly.
- OBSOLETE(AsyncEx): `AwaitCancellableTaskOption`, `AwaitCancellableTaskResult`, `AwaitCancellableValueTaskOption`
- -> `Async.StartTaskImmediate` has overloads supporting `Task` and `ValueTask`, and flows cancellation correctly.
- OBSOLETE(AsyncResult): `ofTaskAction`
- -> `Async.Await >> Async.catch`.
- NOTE did not exist on `TaskResult` or `JobResult`.
- OBSOLETE(AsyncResult, JobResult, TaskResult): `XResult.ofResult`
- -> `X.result`.
- OBSOLETE(AsyncResult, JobResult, TaskResult): `catch`
- -> `catchWith`.
- NOTE BEHAVIOR CHANGE: `Task.catchWith` does NOT trap `OperationCanceledException`/`TaskCanceledException` (the outgoing function did, but this is inconsistent with the FSharp.Core 11 `Task.catch`/`catchWith` semantics).
- OBSOLETE(TaskResult): `ofCatchTask`
- -> `Task.catch`.
- NOTE BEHAVIOR CHANGE: `Task.catch` does NOT trap `OperationCanceledException`/`TaskCanceledException` (the outgoing function did, but this is inconsistent with the FSharp.Core 11 `Task.catch`/`catchWith` semantics).
- [Stragglers from beta003](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/373) Credits @bartelink
- feat(CancellableTask, CancellableValueTask): `result`
- feat(CancellableTaskResult, CancellableTaskValidation): `ok`
- feat(CancellableTaskResult): `error`
- feat(JobOption): `none`
- feat(CancellableTaskValidation, Validation): `errors`
- Renames:
- OBSOLETE(JobOption): `singleton`
- -> `some`.