Last active
December 18, 2015 13:39
-
-
Save vasily-kirichenko/5791396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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