Fsharp-maps
提供:Dev Guides
F#-マップ
F#では、マップは値をキーに関連付ける特別な種類のセットです。 マップは、セットが作成されるのと同様の方法で作成されます。
マップを作成する
Map.emptyを使用して空のマップを作成し、Add関数を使用してアイテムを追加すると、マップが作成されます。 次の例はこれを示しています-
例
あなたがプログラムをコンパイルして実行すると、次の出力が得られます-
キーを使用して、マップ内の個々の要素にアクセスできます。
例
あなたがプログラムをコンパイルして実行すると、次の出力が得られます-
マップの基本操作
モジュール名を追加
次の表は、マップの基本操作を示しています-
Member | Description |
---|---|
Add | Returns a new map with the binding added to the given map. |
ContainsKey | Tests if an element is in the domain of the map. |
Count | The number of bindings in the map. |
IsEmpty | Returns true if there are no bindings in the map. |
Item | Lookup an element in the map. Raises KeyNotFoundException if no binding exists in the map. |
Remove | Removes an element from the domain of the map. No exception is raised if the element is not present. |
TryFind | Lookup an element in the map, returning a Some *value if the element is in the domain of the map and None* if not. |
次の例は、上記の機能のいくつかの使用を示しています-
例
あなたがプログラムをコンパイルして実行すると、次の出力が得られます-