Last active
October 1, 2015 21:33
-
-
Save kevmal/6a83e1fb7246203ba530 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
[<System.Runtime.CompilerServices.Extension>] | |
type ExtensionMethods() = | |
[<System.Runtime.CompilerServices.Extension>] | |
static member inline GetOption< ^a,'k,'v when 'a : (member TryGetValue : 'k * ('v byref) -> bool)>(this : ^a, key : 'k) = | |
let mutable v = Unchecked.defaultof<'v> | |
let scc = ( ^a : (member TryGetValue : 'k * ('v byref) -> bool) this, key, &v) | |
if scc then | |
Some v | |
else | |
None | |
[<System.Runtime.CompilerServices.Extension>] | |
static member inline GetOrDefault< ^a,'k,'v when 'a : (member TryGetValue : 'k * ('v byref) -> bool)>(this : ^a, key : 'k, defaultValue : 'v) = | |
let mutable v = Unchecked.defaultof<'v> | |
let scc = ( ^a : (member TryGetValue : 'k * ('v byref) -> bool) this, key, &v) | |
if scc then | |
v | |
else | |
defaultValue | |
[<System.Runtime.CompilerServices.Extension>] | |
static member inline Bind< ^a,'k,'v when 'a : (member TryGetValue : 'k * ('v byref) -> bool)>(this : ^a, key : 'k, f : 'v -> 'v option) = | |
let mutable v = Unchecked.defaultof<'v> | |
let scc = ( ^a : (member TryGetValue : 'k * ('v byref) -> bool) this, key, &v) | |
if scc then | |
f v | |
else | |
None | |
[<System.Runtime.CompilerServices.Extension>] | |
static member inline Return< ^a,'k,'v when 'a : (member TryGetValue : 'k * ('v byref) -> bool)>(this : ^a, v : 'v) = Some v | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment