FsToolkit.ErrorHandling.TaskResult 4.0.0

.NET Standard 2.0
dotnet add package FsToolkit.ErrorHandling.TaskResult --version 4.0.0
NuGet\Install-Package FsToolkit.ErrorHandling.TaskResult -Version 4.0.0
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.TaskResult" Version="4.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FsToolkit.ErrorHandling.TaskResult --version 4.0.0
#r "nuget: FsToolkit.ErrorHandling.TaskResult, 4.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install FsToolkit.ErrorHandling.TaskResult as a Cake Addin
#addin nuget:?package=FsToolkit.ErrorHandling.TaskResult&version=4.0.0

// Install FsToolkit.ErrorHandling.TaskResult as a Cake Tool
#tool nuget:?package=FsToolkit.ErrorHandling.TaskResult&version=4.0.0

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

Requirements
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)

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

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on FsToolkit.ErrorHandling.TaskResult:

Package Downloads
NBomber.Contracts

Public contracts for NBomber

FsToolkit.ErrorHandling.JobResult

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.

FsToolkit.ErrorHandling.IcedTasks

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.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 2,853 11/19/2022
4.0.0-beta001 29 11/19/2022
3.3.1 239 11/19/2022
3.3.1-beta004 29 11/19/2022
3.3.1-beta003 35 11/18/2022
3.3.1-beta002 31 11/18/2022
3.3.1-beta001 32 11/18/2022
3.3.0-beta001 38 11/9/2022
3.2.0 6,385 10/31/2022
3.2.0-beta001 38 10/31/2022
3.1.0 5,445 10/19/2022
3.0.1 752 10/18/2022
3.0.0 2,341 10/14/2022
3.0.0-beta008 45 10/14/2022
3.0.0-beta007 9,536 4/15/2022
3.0.0-beta006 100 4/5/2022
3.0.0-beta005 71 4/5/2022
3.0.0-beta004 71 4/5/2022
3.0.0-beta003 149 3/30/2022
3.0.0-beta002 90 2/21/2022
3.0.0-beta001 72 2/21/2022
2.13.0 142,047 1/11/2022
2.13.0-beta001 96 1/11/2022
2.12.0 1,060 1/6/2022
2.12.0-beta001 86 1/6/2022
2.11.1 10,262 12/1/2021
2.11.1-beta001 678 12/1/2021
2.11.0 3,933 11/24/2021
2.11.0-beta004 3,084 11/24/2021
2.11.0-beta002 2,971 11/24/2021
2.11.0-beta001 2,867 11/24/2021
2.10.0 11,580 11/13/2021
2.9.0 1,024 11/10/2021
2.9.0-beta001 161 11/10/2021
2.8.1 507 11/7/2021
2.8.0 348 11/7/2021
2.8.0-beta001 228 11/7/2021
2.7.1 1,958 10/19/2021
2.7.1-beta001 200 10/19/2021
2.7.0 11,595 8/2/2021
2.7.0-beta001 196 8/2/2021
2.6.0 2,657 7/7/2021
2.6.0-beta001 189 7/7/2021
2.5.0 8,521 5/26/2021
2.5.0-beta001 189 5/26/2021
2.4.0 622 5/23/2021
2.4.0-beta001 194 5/23/2021
2.3.0 1,779 5/14/2021
2.3.0-beta002 185 5/14/2021
2.2.0 9,896 4/21/2021
2.1.2 20,923 2/27/2021
2.1.1 343 2/26/2021
2.1.1-beta001 182 2/26/2021
2.1.0 401 2/26/2021
2.1.0-beta003 237 2/26/2021
2.1.0-beta002 192 2/25/2021
2.1.0-beta001 186 2/25/2021
2.0.0 264,520 11/20/2020
2.0.0-beta002 312 11/18/2020
2.0.0-beta001 338 8/29/2020
1.4.3 160,160 7/22/2020
1.4.0 3,265 6/5/2020
1.3.2 578 6/5/2020
1.3.1 1,488 5/29/2020
1.3.1-beta001 338 5/25/2020
1.3.0 1,710 5/25/2020
1.3.0-beta006 353 5/25/2020
1.3.0-beta005 379 5/25/2020
1.3.0-beta004 310 5/12/2020
1.2.6 19,252 2/15/2020
1.2.5 13,246 10/18/2019
1.2.4 643 10/10/2019
1.2.3 1,535 7/22/2019
1.2.2 856 5/31/2019
1.2.1 643 5/22/2019
1.1.1 488 5/9/2019
1.1.0 550 5/7/2019

- BREAKING: [Better alignment with FSharp.Core Result functions](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/199). Credits @TheAngryByrd
- [Adding Option.either and friends](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/198). Credits @TheAngryByrd
- [Fixes for Option.tryParse and tryGetValue](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/197). Credits @TheAngryByrd