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: 10/29/2010 7:47:46 PM
- Language: F#
- Type: System.Collections.Generic.IDictionary
- Views: 1802
Double click on the code to select all.