次の方法で共有


Map.tryFind<'Key,'T> 関数 (F#)

マップ内の要素を検索し、要素がマップのドメイン内にある場合は Some 値を返し、そうでない場合は None を返します。

名前空間/モジュール パス: Microsoft.FSharp.Collections.Map

アセンブリ: FSharp.Core (FSharp.Core.dll 内)

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

// Usage:
Map.tryFind key table

パラメーター

  • key
    型: 'Key

    入力キー。

  • table
    型: Map<'Key,'T>

    入力マップ。

戻り値

見つかった Some 値または None。

解説

この関数は、コンパイルされたアセンブリでは TryFind という名前です。F# 以外の言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

使用例

Map.tryFind の使用方法を次のコード例に示します。

let map1 = [ for i in 1 .. 100 -> (i, i*i) ] |> Map.ofList
let result = Map.tryFind 50 map1
match result with
| Some x -> printfn "Found %d." x
| None -> printfn "Did not find the specified value."

出力

  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリのバージョン

サポート: ポータブル 2.0、4.0

参照

関連項目

Collections.Map モジュール (F#)

Microsoft.FSharp.Collections 名前空間 (F#)