Created
August 26, 2015 09:00
-
-
Save janderit/3cd7a56ad0ad30c99294 to your computer and use it in GitHub Desktop.
Option evaluation operator for F#
This file contains hidden or 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
type OptionDefault<'a> = | |
| Default of 'a | |
| Lazy of (unit->'a) | |
| Expected of reason:string | |
let (|.) (opt:'a option) (def:OptionDefault<'a>) : 'a = | |
match opt with | |
| Some (v) -> v | |
| None -> | |
match def with | |
| Default(v) -> v | |
| Lazy(factory) -> factory () | |
| Expected(reason) -> failwith reason |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment