Map.tryFindKey<'Key,'T> Function (F#)
Returns the key of the first mapping in the collection that satisfies the given predicate, or returns None if no such element exists.
Namespace/Module Path: Microsoft.FSharp.Collections.Map
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
Map.tryFindKey : ('Key -> 'T -> bool) -> Map<'Key,'T> -> 'Key option (requires comparison)
// Usage:
Map.tryFindKey predicate table
Parameters
predicate
Type: 'Key -> 'T -> boolThe function to test the input elements.
table
Type: Map<'Key,'T>The input map.
Return Value
The first key for which the predicate returns true or None if the predicate evaluates to false for each key/value pair.
Remarks
This function is named TryFindKey in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.
Example
The following code shows the use of the Map.tryFindKey function.
let map1 = [ for i in 1 .. 100 -> (i, i*i) ] |> Map.ofList
let result = Map.tryFindKey (fun key value -> key = value) map1
match result with
| Some key -> printfn "Found element with key %d." key
| None -> printfn "Did not find any element that matches the condition."
Output
Found element with key 1.
Platforms
Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3