Skip to content

Instantly share code, notes, and snippets.

@janderit
Created August 26, 2015 09:00
Show Gist options
  • Save janderit/3cd7a56ad0ad30c99294 to your computer and use it in GitHub Desktop.
Save janderit/3cd7a56ad0ad30c99294 to your computer and use it in GitHub Desktop.
Option evaluation operator for F#
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