namespace Foo open System open System.Collections.Generic [<AutoOpen>] module FsExtensions = type IDictionary<'Key,'Value> with /// Attempts to get the value associated with the specified key. member this.TryGet key = let ok, v = this.TryGetValue key if ok then Some v else NoneExample:
match myDict.TryGet "foo" with | Some(v) -> printfn "Found %A" v | None -> printfn "Not found!"
Like IDictionary<>.TryGetValue, but returns the result as an Option, which is more convenient to work with from F#.
- Author: Joel Mueller
- Submitted on: 29-10-2010 19:47:46
- Language: F#
- Type: System.Collections.Generic.IDictionary
- Views: 3033
Double click on the code to select all.