FsToolkit.ErrorHandling
2.13.0
See the version list below for details.
Install-Package FsToolkit.ErrorHandling -Version 2.13.0
dotnet add package FsToolkit.ErrorHandling --version 2.13.0
<PackageReference Include="FsToolkit.ErrorHandling" Version="2.13.0" />
paket add FsToolkit.ErrorHandling --version 2.13.0
#r "nuget: FsToolkit.ErrorHandling, 2.13.0"
// Install FsToolkit.ErrorHandling as a Cake Addin
#addin nuget:?package=FsToolkit.ErrorHandling&version=2.13.0
// Install FsToolkit.ErrorHandling as a Cake Tool
#tool nuget:?package=FsToolkit.ErrorHandling&version=2.13.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
- The main resource as to learning this style of programming Railway Oriented Programming
- However Result isn't a panacea, see what pitfalls and where you shouldn't use
Result
. In defense of Exceptions: Throw (away) your Result
Builds
GitHub Actions |
---|
NuGet
Package name | Badge |
---|---|
FsToolkit.ErrorHandling | |
FsToolkit.ErrorHandling.TaskResult | |
FsToolkit.ErrorHandling.JobResult | |
FsToolkit.ErrorHandling.AsyncSeq |
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):
<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 |
.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 |
-
.NETStandard 2.0
- FSharp.Core (>= 4.7.2)
NuGet packages (12)
Showing the top 5 NuGet packages that depend on FsToolkit.ErrorHandling:
Package | Downloads |
---|---|
FsToolkit.ErrorHandling.TaskResult
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. |
|
Oryx
.NET SDK for writing web clients |
|
FsToolkit.ErrorHandling.AsyncSeq
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. |
|
WldMr.Excel.Functions
Generic Excel functions written with ExcelDna and F#. Mostly Array and String related-operations. |
|
WldMr.Excel.Core
F# types and functions to author safe and full-featured Excel functions with Excel-DNA |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.0-beta007 | 3,282 | 4/15/2022 |
3.0.0-beta006 | 98 | 4/5/2022 |
3.0.0-beta005 | 61 | 4/5/2022 |
3.0.0-beta004 | 61 | 4/5/2022 |
3.0.0-beta003 | 145 | 3/30/2022 |
3.0.0-beta002 | 604 | 2/21/2022 |
3.0.0-beta001 | 58 | 2/21/2022 |
2.13.0 | 97,737 | 1/11/2022 |
2.13.0-beta001 | 75 | 1/11/2022 |
2.12.0 | 1,964 | 1/6/2022 |
2.12.0-beta001 | 74 | 1/6/2022 |
2.11.1 | 19,746 | 12/1/2021 |
2.11.1-beta001 | 649 | 12/1/2021 |
2.11.0 | 5,670 | 11/24/2021 |
2.11.0-beta004 | 3,082 | 11/24/2021 |
2.11.0-beta002 | 3,034 | 11/24/2021 |
2.11.0-beta001 | 2,869 | 11/24/2021 |
2.10.0 | 20,821 | 11/13/2021 |
2.9.0 | 3,849 | 11/10/2021 |
2.9.0-beta001 | 163 | 11/10/2021 |
2.8.1 | 2,694 | 11/7/2021 |
2.8.0 | 360 | 11/7/2021 |
2.8.0-beta001 | 244 | 11/7/2021 |
2.7.1 | 7,023 | 10/19/2021 |
2.7.1-beta001 | 220 | 10/19/2021 |
2.7.0 | 44,330 | 8/2/2021 |
2.7.0-beta001 | 231 | 8/2/2021 |
2.6.0 | 33,096 | 7/7/2021 |
2.6.0-beta001 | 224 | 7/7/2021 |
2.5.0 | 42,147 | 5/26/2021 |
2.5.0-beta001 | 218 | 5/26/2021 |
2.4.0 | 6,357 | 5/23/2021 |
2.4.0-beta001 | 219 | 5/23/2021 |
2.3.0 | 8,498 | 5/14/2021 |
2.3.0-beta002 | 205 | 5/14/2021 |
2.2.0 | 12,218 | 4/21/2021 |
2.1.2 | 50,813 | 2/27/2021 |
2.1.1 | 577 | 2/26/2021 |
2.1.1-beta001 | 208 | 2/26/2021 |
2.1.0 | 410 | 2/26/2021 |
2.1.0-beta003 | 271 | 2/26/2021 |
2.1.0-beta002 | 216 | 2/25/2021 |
2.1.0-beta001 | 212 | 2/25/2021 |
2.0.0 | 215,854 | 11/20/2020 |
2.0.0-beta002 | 350 | 11/18/2020 |
2.0.0-beta001 | 758 | 8/29/2020 |
1.4.3 | 172,303 | 7/22/2020 |
1.4.0 | 5,893 | 6/5/2020 |
1.3.2 | 602 | 6/5/2020 |
1.3.1 | 2,360 | 5/29/2020 |
1.3.1-beta001 | 398 | 5/25/2020 |
1.3.0 | 2,352 | 5/25/2020 |
1.3.0-beta006 | 417 | 5/25/2020 |
1.3.0-beta005 | 435 | 5/25/2020 |
1.3.0-beta004 | 560 | 5/12/2020 |
1.2.6 | 31,141 | 2/15/2020 |
1.2.5 | 23,469 | 10/18/2019 |
1.2.4 | 1,100 | 10/10/2019 |
1.2.3 | 82,149 | 7/22/2019 |
1.2.2 | 4,797 | 5/31/2019 |
1.2.1 | 23,118 | 5/22/2019 |
1.1.1 | 1,061 | 5/9/2019 |
1.1.0 | 694 | 5/7/2019 |
1.0.0 | 3,924 | 4/10/2019 |
0.0.14 | 1,855 | 1/27/2019 |
0.0.13 | 551 | 1/21/2019 |
0.0.12 | 879 | 1/4/2019 |
0.0.11 | 573 | 1/3/2019 |
0.0.10 | 603 | 12/30/2018 |
0.0.9 | 824 | 10/5/2018 |
0.0.8 | 630 | 10/5/2018 |
0.0.7 | 647 | 10/5/2018 |
0.0.6 | 618 | 10/4/2018 |
0.0.5 | 618 | 9/16/2018 |
0.0.4 | 633 | 9/16/2018 |
0.0.3 | 648 | 9/8/2018 |
0.0.2 | 648 | 9/8/2018 |
0.0.1 | 685 | 9/8/2018 |
- [Option/ValueOption.ofNull and bindNull](https://github.com/demystifyfp/FsToolkit.ErrorHandling/pull/164) Credits [@TheAngryByrd](https://github.com/TheAngryByrd)