FsToolkit.ErrorHandling.TaskResult 4.15.2-beta001

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 and .NET Framework 4.6.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 infomation 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 exhausting 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 {
    // requireSome unwraps a Some value or gives the specified error if None
    let! user = username |> tryGetUser |> AsyncResult.requireSome InvalidUser

    // requireTrue gives the specified error if false
    do! user |> isPwdValid password |> Result.requireTrue 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)

Ajira Technologies, India

Showing the top 20 packages that depend on FsToolkit.ErrorHandling.TaskResult.

Packages Downloads
NBomber
Modern and flexible load testing framework for Pull and Push scenarios, designed to test any system regardless a protocol (HTTP/WebSockets/AMQP etc) or a semantic model (Pull/Push).
12
NBomber.Contracts
Public contracts for NBomber
12
NBomber
Modern and flexible load testing framework for Pull and Push scenarios, designed to test any system regardless a protocol (HTTP/WebSockets/AMQP etc) or a semantic model (Pull/Push).
11

- [Fix AsyncValidationCE binding against asyncResult](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/260) Credits @1eyewonder

.NET Standard 2.0

.NET Standard 2.1

Version Downloads Last updated
4.18.0 13 11/27/2024
4.18.0-beta001 9 11/27/2024
4.17.0 12 11/27/2024
4.17.0-beta002 9 11/27/2024
4.17.0-beta001 9 11/27/2024
4.16.0 11 11/11/2024
4.15.3 12 11/27/2024
4.15.3-beta001 10 11/27/2024
4.15.2 11 10/20/2024
4.15.2-beta001 10 11/08/2024
4.15.1 11 11/27/2024
4.15.0 8 11/27/2024
4.14.0 11 11/27/2024
4.13.0 10 11/12/2024
4.13.0-beta002 11 10/20/2024
4.13.0-beta001 10 11/06/2024
4.12.0 13 11/13/2024
4.11.1 12 11/27/2024
4.11.0 12 11/27/2024
4.10.0 11 11/27/2024
4.9.0 11 11/10/2024
4.8.0 12 11/09/2024
4.7.0 11 11/17/2024
4.7.0-beta001 9 11/11/2024
4.6.0 10 11/13/2024
4.6.0-beta001 9 11/11/2024
4.5.0 8 10/20/2024
4.5.0-beta002 10 11/27/2024
4.5.0-beta001 12 11/04/2024
4.4.0 11 11/19/2024
4.3.0 10 10/26/2024
4.2.1 12 11/27/2024
4.2.0 12 11/08/2024
4.1.0 11 11/27/2024
4.1.0-beta001 10 11/27/2024
4.0.0 11 10/27/2024
4.0.0-beta001 8 11/27/2024
3.3.1 10 11/04/2024
3.3.1-beta004 6 11/27/2024
3.3.1-beta003 10 11/08/2024
3.3.1-beta002 12 11/08/2024
3.3.1-beta001 6 11/11/2024
3.3.0-beta001 9 11/07/2024
3.2.0 11 10/20/2024
3.2.0-beta001 9 11/27/2024
3.1.0 11 11/27/2024
3.0.1 11 11/13/2024
3.0.0 12 11/07/2024
3.0.0-beta008 11 10/31/2024
3.0.0-beta007 11 10/26/2024
3.0.0-beta006 11 11/27/2024
3.0.0-beta005 11 11/27/2024
3.0.0-beta004 10 11/27/2024
3.0.0-beta003 12 11/27/2024
3.0.0-beta002 12 11/10/2024
3.0.0-beta001 6 10/21/2024
2.13.0 11 10/21/2024
2.13.0-beta001 8 11/27/2024
2.12.0 13 11/27/2024
2.12.0-beta001 8 11/27/2024
2.11.1 8 11/14/2024
2.11.1-beta001 6 11/27/2024
2.11.0 11 10/21/2024
2.11.0-beta004 8 11/27/2024
2.11.0-beta002 8 11/27/2024
2.11.0-beta001 11 11/27/2024
2.10.0 12 11/11/2024
2.9.0 13 10/19/2024
2.9.0-beta001 9 11/27/2024
2.8.1 11 11/17/2024
2.8.0 6 11/27/2024
2.8.0-beta001 10 10/21/2024
2.7.1 10 11/27/2024
2.7.1-beta001 11 11/06/2024
2.7.0 13 11/27/2024
2.7.0-beta001 12 10/20/2024
2.6.0 11 11/10/2024
2.6.0-beta001 9 11/27/2024
2.5.0 11 11/27/2024
2.5.0-beta001 10 11/13/2024
2.4.0 11 10/27/2024
2.4.0-beta001 11 10/20/2024
2.3.0 10 11/12/2024
2.3.0-beta002 10 11/27/2024
2.2.0 8 10/20/2024
2.1.2 12 10/27/2024
2.1.1 11 01/19/2025
2.1.1-beta001 10 11/17/2024
2.1.0 11 11/07/2024
2.1.0-beta003 8 11/27/2024
2.1.0-beta002 11 11/27/2024
2.1.0-beta001 9 11/16/2024
2.0.0 10 11/27/2024
2.0.0-beta002 12 11/27/2024
2.0.0-beta001 10 11/27/2024
1.4.3 10 11/27/2024
1.4.0 11 11/23/2024
1.3.2 10 10/19/2024
1.3.1 11 11/27/2024
1.3.1-beta001 8 11/27/2024
1.3.0 12 11/27/2024
1.3.0-beta006 10 11/27/2024
1.3.0-beta005 9 11/27/2024
1.3.0-beta004 10 11/26/2024
1.2.6 12 11/27/2024
1.2.5 12 11/14/2024
1.2.4 11 11/12/2024
1.2.3 10 11/07/2024
1.2.2 11 10/20/2024
1.2.1 11 11/08/2024
1.1.1 12 10/19/2024
1.1.0 11 11/10/2024