다음을 통해 공유


Map.findKey<'Key,'T> 함수(F#)

컬렉션에 있는 각 매핑에서 함수를 실행하고 함수가 true를 반환하는 첫 매핑에 대한 키를 반환합니다.이러한 요소가 없으면 이 기능은 KeyNotFoundException을 발생시킵니다.

네임스페이스/모듈 경로: Microsoft.FSharp.Collections.Map

어셈블리: FSharp.Core(FSharp.Core.dll)

// Signature:
Map.findKey : ('Key -> 'T -> bool) -> Map<'Key,'T> -> 'Key (requires comparison)

// Usage:
Map.findKey predicate table

매개 변수

  • predicate
    형식: 'Key -> 'T ->bool

    입력 요소를 테스트하는 함수입니다.

  • table
    형식: Map<'Key,'T>

    입력 맵입니다.

예외

Exception

조건

KeyNotFoundException

키가 맵에 없는 경우 throw됩니다.

반환 값

조건자가 true가 되는 첫 번째 키입니다.

설명

컴파일된 어셈블리에서 이 함수의 이름은 FindKey입니다.F# 이외의 언어에서 함수에 액세스하거나 리플렉션을 통해 함수에 액세스하는 경우 이 이름을 사용합니다.

예제

다음 예제에서는 Map.findKey의 사용 방법을 보여 줍니다.

let findKeyFromValue findValue map =
    printfn "With value %A, found key %A." findValue (Map.findKey (fun key value -> value = findValue) map)
let map1 = Map.ofList [ (1, "one"); (2, "two"); (3, "three") ]
let map2 = Map.ofList [ for i in 1 .. 10 -> (i, i*i) ]
try
    findKeyFromValue "one" map1
    findKeyFromValue "two" map1
    findKeyFromValue 9 map2
    findKeyFromValue 25 map2
    // The key is not in the map, so the following line throws an exception.
    findKeyFromValue 0 map2
with
     :? System.Collections.Generic.KeyNotFoundException as e -> printfn "%s" e.Message

Output

  
  
  
  
  

플랫폼

Windows Windows 서버 2012, Windows Server 2008 R2, Windows 7, 8

버전 정보

F# 코어 라이브러리 버전

지원: 2.0, 4.0, 노트북

참고 항목

참조

Collections.Map 모듈(F#)

Microsoft.FSharp.Collections 네임스페이스(F#)