FsToolkit.ErrorHandling.TaskResult 2.11.0-beta002

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 Badge
FsToolkit.ErrorHandling NuGet
FsToolkit.ErrorHandling.TaskResult NuGet
FsToolkit.ErrorHandling.JobResult NuGet

Developing locally

Requirements

  • .NET Core SDK
    • v3.1.200 or higher
    • Install from here.
  • Node
    • v10.15.0 or LTS
    • Not required but recommend that you use NVM to easily manage multiple versions of Node

Compiling

> build.cmd <optional buildtarget> // on windows
$ ./build.sh  <optional buildtarget>// on unix

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).
15
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).
14
NBomber
Very simple load testing framework for Pull and Push scenarios.
14

- [integrates FsToolkit.ErrorHandling.AsyncSeq into main repository] Credits [@njlr](https://github.com/njlr)

.NET Standard 2.0

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