Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Last active December 18, 2015 13:39
Show Gist options
  • Save vasily-kirichenko/5791396 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/5791396 to your computer and use it in GitHub Desktop.
open FSharpx
open FSharpx.Choice
type Error = Error of string
type AuthLevel = Admin | Normal | Guest
let getSetting = function
| "user" -> Choice1Of2 "user1"
| name -> name |> sprintf "setting %s was not found" |> Error |> Choice2Of2
let getAuth = function
| "user1" -> Choice1Of2 Normal
| user -> user |> sprintf "user %s was not found" |> Error |> Choice2Of2
let log = printfn "%s"
let getAuthorizationLevel = getSetting >=> getAuth
let authLevel =
getAuthorizationLevel "user"
|> Choice.choice id (fun (Error error) -> log error; Guest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment