DefaultDict<'K, 'V> Type
A Collections.Generic.Dictionary<'K,'V> with default Values that get created upon accessing a missing key.
If accessing a non exiting key , the default function is called to create and set it.
Inspired by the defaultdict in Python.
If you need to provide a custom implementation of the default function depending on each key,
then use the Dict<'K,'V> type and its method
Constructors
| Constructor |
Description
|
Full Usage:
DefaultDict(defaultOfKeyFun)
Parameters:
'K -> 'V
-
('K->'V): The function to create a default value from the key
Returns: DefaultDict<'K, 'V>
|
A Collections.Generic.Dictionary with default Values that get created upon accessing a key. If accessing a non exiting key , the default function is called on the key to create the value and set it. Similar to defaultDic in Python
|
Instance members
| Instance member |
Description
|
Full Usage:
this.Add
Parameters:
'K
-
The key to add.
v : 'V
-
The value to add.
|
Add the specified key and value to the DefaultDict. Like Dictionary.Add, it throws an ArgumentException if the key already exists. Use .Set(key, value) or the indexer to add or replace a value.
|
Full Usage:
this.AsString
Returns: string
|
A string representation of the DefaultDict including the count of entries, the first 5 entries and the last entry. When used in Fable this member is inlined for reflection to work.
|
Full Usage:
this.Clear
|
Removes all keys and values from the DefaultDict |
Full Usage:
this.ContainsKey
Parameters:
'K
-
The key to look for.
Returns: bool
|
Determines whether the DefaultDict contains the specified key. Does not create a missing key.
|
Full Usage:
this.ContainsValue
Parameters:
'V
-
The value to look for.
Returns: bool
|
Determines whether the DefaultDict contains a specific value.
|
Full Usage:
this.Count
Returns: int
|
Gets the number of key/value pairs contained in the DefaultDict
|
Full Usage:
this.DoesNotContainKey
Parameters:
'K
-
The key to look for.
Returns: bool
|
Determines whether the DefaultDict does not contain the specified key.
Same as
|
Full Usage:
this.Get
Parameters:
'K
-
The key to look up.
Returns: 'V
|
Get value for given key. Calls defaultFun to get value if key not found. Also sets key to returned value. Use .TryGetValue(k) if you don't want a missing key to be created
|
|
Returns an enumerator that iterates through the DefaultDict.
|
|
Access the underlying Collections.Generic.Dictionary<'K,'V>. ATTENTION! This is not even a shallow copy, mutating it will also change this instance of DefaultDict!
|
Full Usage:
this[k]
Returns: 'K
|
For Index operator .[i]: get or set the value for a given key Calls defaultFun to get value if key not found. Also sets the key to returned value. Use dict.TryGetValue(k) if you don't want a missing key to be created on the DefaultDict
|
Full Usage:
this.Items
Returns: ('K * 'V) seq
|
Returns a (lazy) sequence of key and value tuples
|
|
Gets a collection containing the keys in the DefaultDict
|
Full Usage:
this.Pop
Parameters:
'K
-
The key to remove.
Returns: 'V
The value that was stored at the key.
|
Get a value and remove the key and value from the DefaultDict, like *.pop() in Python. Throws a KeyNotFoundException if the key does not exist. Does not create a missing key.
|
Full Usage:
this.Remove
Parameters:
'K
-
The key to remove.
Returns: bool
true if the key was found and removed, false if not.
|
Removes the value with the specified key from the DefaultDict. See also the .Pop(key) method that returns the removed value.
|
Full Usage:
this.Set
Parameters:
'K
-
The key to set.
value : 'V
-
The value to set.
|
Set value for given key, adds the key if it is missing. Same as the indexer setter.
|
Full Usage:
this.ToString
Parameters:
int
-
The maximum number of entries to show. Zero or less shows only the header.
Returns: string
|
A string representation of the DefaultDict including the count of entries, the specified amount of entries and the last entry. When used in Fable this member is inlined for reflection to work.
|
Full Usage:
this.TryGetValue
Parameters:
'K
-
The key to look up.
Returns: bool * 'V
true and the value if the key was found, false and the default of 'V if not.
|
Gets the value associated with the specified key. As opposed to Get(key) this does not create a key if it is missing.
|
Full Usage:
this.TryPop
Parameters:
'K
-
The key to remove.
Returns: 'V option
Some value if the key was found, None if not.
|
Try to get a value and remove the key and value from the DefaultDict, like *.pop() in Python. Does not create a missing key.
|
|
Gets a collection containing the values in the DefaultDict
|
Static members
| Static member |
Description
|
Full Usage:
DefaultDict.create defaultOfKeyFun keysValues
Parameters:
'K -> 'V
-
The function to create a default value from a missing key.
keysValues : ('K * 'V) seq
-
The key and value pairs to fill the new DefaultDict with.
Returns: DefaultDict<'K, 'V>
|
Constructs a new DefaultDict from seq of key and value pairs. Like the Dictionary constructor, it throws an ArgumentException on duplicate keys.
|
Full Usage:
DefaultDict.createDirectly defaultOfKeyFun di
Parameters:
'K -> 'V
-
The function to create a default value from a missing key.
di : Dictionary<'K, 'V>
-
The Dictionary to wrap. Changes to it show in the new DefaultDict and the other way round.
Returns: DefaultDict<'K, 'V>
|
Constructs a new DefaultDict by using the supplied Dictionary<'K,'V> directly, without any copying of items.
|
Full Usage:
DefaultDict.get key dd
Parameters:
'K
-
The key to look up.
dd : DefaultDict<'K, 'V>
-
The DefaultDict to read from.
Returns: 'V
|
Get value for given key.
Calls defaultFun to get value if key not found, and sets it.
Same as
|
Full Usage:
DefaultDict.set key value dd
Parameters:
'K
-
The key to set.
value : 'V
-
The value to set.
dd : DefaultDict<'K, 'V>
-
The DefaultDict to change.
|
Set value for given key, adds the key if it is missing.
Same as
|
Dicts