Skip to content

Repository files navigation

PCT.ErrorHandling

Error handling with F# easily.

Installation

Downloaf from the release.

Using dotnet CLI to install downloaded packages.

dotnet add package PCT.ErrorHandling --source ".\YourPkgDownloadDir"

Or using a powershell cmdlet.

Install-Package PCT.ErrorHandling -Source ".\YourPkgDownloadDir"

Quick Start

open System.IO
open PCT.ErrorHandling

type AccessLevel =
    | Administrator
    | User
    | Tourists

type Account = {
    name: string
    access: AccessLevel
}

let validateAdmin (acc: Account) =
    Resultx.ensure (acc.access = AccessLevel.Administrator) 5 "Access is denied"

let loginControlPanel (acc: Account) =
    match validateAdmin acc with
        | Ok _ -> printfn "Hello, %s" acc.name
        | Error err -> 
            printfn "Error: %A" err
            printfn "You don't have correct access."

let startApp () = 
    let accounts = [ { name = "Alex"; access = Administrator }; { name = "Steve"; access = User } ]
    accounts |> List.iter (fun acc -> loginControlPanel acc)

Help document

wip.

About

Error handling with F#

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages