Last active
October 1, 2015 21:33
Revisions
-
kevmal renamed this gist
Jun 20, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kevmal created this gist
Jun 20, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ [<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