Logo Dicts

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 dict.GetOrSetDefault func key.

Constructors

Constructor Description

DefaultDict(defaultOfKeyFun)

Full Usage: DefaultDict(defaultOfKeyFun)

Parameters:
    defaultOfKeyFun : '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

defaultOfKeyFun : 'K -> 'V

('K->'V): The function to create a default value from the key

Returns: DefaultDict<'K, 'V>

Instance members

Instance member Description

this.Add

Full Usage: this.Add

Parameters:
    k : '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.

k : 'K

The key to add.

v : 'V

The value to add.

this.AsString

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.

Returns: string

this.Clear

Full Usage: this.Clear

Removes all keys and values from the DefaultDict

this.ContainsKey

Full Usage: this.ContainsKey

Parameters:
    k : 'K - The key to look for.

Returns: bool

Determines whether the DefaultDict contains the specified key. Does not create a missing key.

k : 'K

The key to look for.

Returns: bool

this.ContainsValue

Full Usage: this.ContainsValue

Parameters:
    v : 'V - The value to look for.

Returns: bool

Determines whether the DefaultDict contains a specific value.

v : 'V

The value to look for.

Returns: bool

this.Count

Full Usage: this.Count

Returns: int

Gets the number of key/value pairs contained in the DefaultDict

Returns: int

this.DoesNotContainKey

Full Usage: this.DoesNotContainKey

Parameters:
    key : 'K - The key to look for.

Returns: bool

Determines whether the DefaultDict does not contain the specified key. Same as not(dic.ContainsKey(key))

key : 'K

The key to look for.

Returns: bool

this.Get

Full Usage: this.Get

Parameters:
    k : '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

k : 'K

The key to look up.

Returns: 'V

this.GetEnumerator

Full Usage: this.GetEnumerator

Returns: Enumerator<'K, 'V>

Returns an enumerator that iterates through the DefaultDict.

Returns: Enumerator<'K, 'V>

this.InternalDictionary

Full Usage: this.InternalDictionary

Returns: Dictionary<'K, 'V>

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!

Returns: Dictionary<'K, 'V>

this[k]

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

Returns: 'K

this.Items

Full Usage: this.Items

Returns: ('K * 'V) seq

Returns a (lazy) sequence of key and value tuples

Returns: ('K * 'V) seq

this.Keys

Full Usage: this.Keys

Returns: KeyCollection<'K, 'V>

Gets a collection containing the keys in the DefaultDict

Returns: KeyCollection<'K, 'V>

this.Pop

Full Usage: this.Pop

Parameters:
    k : '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.

k : 'K

The key to remove.

Returns: 'V

The value that was stored at the key.

this.Remove

Full Usage: this.Remove

Parameters:
    k : '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.

k : 'K

The key to remove.

Returns: bool

true if the key was found and removed, false if not.

this.Set

Full Usage: this.Set

Parameters:
    key : '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.

key : 'K

The key to set.

value : 'V

The value to set.

this.ToString

Full Usage: this.ToString

Parameters:
    entriesToPrint : 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.

entriesToPrint : int

The maximum number of entries to show. Zero or less shows only the header.

Returns: string

this.TryGetValue

Full Usage: this.TryGetValue

Parameters:
    k : '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.

k : '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.

this.TryPop

Full Usage: this.TryPop

Parameters:
    k : '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.

k : 'K

The key to remove.

Returns: 'V option

Some value if the key was found, None if not.

this.Values

Full Usage: this.Values

Returns: ValueCollection<'K, 'V>

Gets a collection containing the values in the DefaultDict

Returns: ValueCollection<'K, 'V>

Static members

Static member Description

DefaultDict.create defaultOfKeyFun keysValues

Full Usage: DefaultDict.create defaultOfKeyFun keysValues

Parameters:
    defaultOfKeyFun : '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.

defaultOfKeyFun : '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>

DefaultDict.createDirectly defaultOfKeyFun di

Full Usage: DefaultDict.createDirectly defaultOfKeyFun di

Parameters:
    defaultOfKeyFun : '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.

defaultOfKeyFun : '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>

DefaultDict.get key dd

Full Usage: DefaultDict.get key dd

Parameters:
    key : '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 dd.Get key

key : 'K

The key to look up.

dd : DefaultDict<'K, 'V>

The DefaultDict to read from.

Returns: 'V

DefaultDict.set key value dd

Full Usage: DefaultDict.set key value dd

Parameters:
    key : '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 dd.Set key value

key : 'K

The key to set.

value : 'V

The value to set.

dd : DefaultDict<'K, 'V>

The DefaultDict to change.

Type something to start searching.