ExtensionMethod.NET Home of 841 C#, Visual Basic, F# and Javascript extension methods


Like IDictionary<>.TryGetValue, but returns the result as an Option, which is more convenient to work with from F#.


namespace Foo

open System
open System.Collections.Generic

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 None


match myDict.TryGet "foo" with
| Some(v) -> printfn "Found %A" v
| None    -> printfn "Not found!"

Author: Joel Mueller

Submitted on: 29 okt 2010

Language: F#

Type: System.Collections.Generic.IDictionary

Views: 3924