Header menu 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 it's method Dicts.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
    v : 'V

Add the specified key and value to the DefaultDict.

k : 'K
v : 'V

this.AsString

Full Usage: this.AsString

Returns: string

A string representation of the DefaultDict including the count of entries and the first 5 entries. 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

Returns: bool

Determines whether the DefaultDict contains the specified key.

k : 'K
Returns: bool

this.ContainsValue

Full Usage: this.ContainsValue

Parameters:
    v : 'V

Returns: bool

Determines whether the DefaultDict contains a specific value.

v : 'V
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

Returns: bool

Determines whether the DefaultDict does not contains the specified key. not(dic.ContainsKey(key))

key : 'K
Returns: bool

this.Get

Full Usage: this.Get

Parameters:
    k : 'K

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

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

Returns: 'V

Get a value and remove key and value it from Dictionary, like *.pop() in Python Will fail if key does not exist Does not set any new key if key is missing

k : 'K
Returns: 'V

this.Remove

Full Usage: this.Remove

Parameters:
    k : 'K

Returns: bool

Removes the value with the specified key from the DefaultDict. See also .Pop(key) method to get the contained value too.

k : 'K
Returns: bool

this.Set

Full Usage: this.Set

Parameters:
    key : 'K
    value : 'V

Set value for given key, same as Dicts.Add(key, value)

key : 'K
value : 'V

this.ToString

Full Usage: this.ToString

Parameters:
    entriesToPrint : int

Returns: string

A string representation of the DefaultDict including the count of entries and the specified amount of entries. When used in Fable this member is inlined for reflection to work.

entriesToPrint : int
Returns: string

this.TryGetValue

Full Usage: this.TryGetValue

Parameters:
    k : 'K

Returns: bool * 'V

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
Returns: bool * 'V

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
    keysValues : ('K * 'V) seq

Returns: DefaultDict<'K, 'V>

Constructs a new DefaultDict from seq of key and value pairs

defaultOfKeyFun : 'K -> 'V
keysValues : ('K * 'V) seq
Returns: DefaultDict<'K, 'V>

DefaultDict.createDirectly defaultOfKeyFun di

Full Usage: DefaultDict.createDirectly defaultOfKeyFun di

Parameters:
    defaultOfKeyFun : 'K -> 'V
    di : Dictionary<'K, 'V>

Returns: DefaultDict<'K, 'V>

Constructs a new DefaultDict by using the supplied Dictionary<'K,'V> directly, without any copying of items

defaultOfKeyFun : 'K -> 'V
di : Dictionary<'K, 'V>
Returns: DefaultDict<'K, 'V>

DefaultDict.get dd key

Full Usage: DefaultDict.get dd key

Parameters:
Returns: 'V

Get value for given key.

dd : DefaultDict<'K, 'V>
key : 'K
Returns: 'V

DefaultDict.set dd key value

Full Usage: DefaultDict.set dd key value

Parameters:

Set value for given key, same as Dicts.Add(key, value)

dd : DefaultDict<'K, 'V>
key : 'K
value : 'V

Type something to start searching.