Dict Module
Static Functions on IDictionary Interface
Functions and values
| Function or value |
Description
|
Full Usage:
Dict.add key value dic
Parameters:
'Key
-
The key to add.
value : 'Value
-
The value to add.
dic : IDictionary<'Key, 'Value>
-
The dictionary to change.
Type parameters: 'Key, 'Value |
Add a key and value to a IDictionary. Like Dictionary.Add, it throws an ArgumentException if the key already exists. Use Dict.set to add or replace a value.
|
Full Usage:
Dict.addIfKeyAbsent key value dic
Parameters:
'Key
-
The key to set.
value : 'Value
-
The value to set if the key is missing.
dic : IDictionary<'Key, 'Value>
-
The dictionary to change.
Returns: bool
true if the value was set, false if the key already existed and nothing was changed.
Type parameters: 'Key, 'Value |
Set value only if key does not exist yet.
Same as
|
Full Usage:
Dict.create xs
Parameters:
('Key * 'Value) seq
-
The key and value pairs to fill the new Dict with.
Returns: Dict<'Key, 'Value>
Type parameters: 'Key, 'Value (requires equality) |
Create a Dict from seq of key and value pairs. Like the Dictionary constructor, it throws an ArgumentException on duplicate keys.
|
Full Usage:
Dict.get key dic
Parameters:
'Key
-
The key to look up.
dic : IDictionary<'Key, 'Value>
-
The dictionary to read from.
Returns: 'Value
Type parameters: 'Key, 'Value |
Get value at key from IDictionary, with nicer Error messages. Throws a KeyNotFoundException if the key is not found.
|
Full Usage:
Dict.getOrSetDefault getDefault key dic
Parameters:
'Key -> 'Value
-
The function to create the value from the key, only called if the key is missing.
key : 'Key
-
The key to look up.
dic : IDictionary<'Key, 'Value>
-
The dictionary to read from and change.
Returns: 'Value
The existing or the newly created value.
Type parameters: 'Key, 'Value |
If the key is not present calls the default function, sets its result as value at the key and returns it. This function is an alternative to the DefaultDict type. Use it if you need to provide a custom implementation of the default function depending on the key.
|
Full Usage:
Dict.getOrSetDefaultValue defaultValue key dic
Parameters:
'Value
-
The value to set if the key is missing.
key : 'Key
-
The key to look up.
dic : IDictionary<'Key, 'Value>
-
The dictionary to read from and change.
Returns: 'Value
The existing value or the default value.
Type parameters: 'Value, 'Key |
If the key is not present sets the default value at the key and returns it.
|
Full Usage:
Dict.items dic
Parameters:
IDictionary<'Key, 'Value>
-
The dictionary to read from.
Returns: ('Key * 'Value) seq
Type parameters: 'Key, 'Value |
Returns a (lazy) sequence of key and value tuples.
|
Full Usage:
Dict.iter f dic
Parameters:
'Key -> 'Value -> unit
-
The function to call with each key and value.
dic : IDictionary<'Key, 'Value>
-
The dictionary to iterate over.
Type parameters: 'Key, 'Value |
Iterate over keys and values of a dictionary.
|
Full Usage:
Dict.keys dic
Parameters:
IDictionary<'Key, 'Value>
-
The dictionary to read from.
Returns: 'Key seq
Type parameters: 'Key, 'Value |
Returns a (lazy) sequence of keys.
|
Full Usage:
Dict.map f dic
Parameters:
'Key -> 'Value -> 'T
-
The function to call with each key and value.
dic : IDictionary<'Key, 'Value>
-
The dictionary to map over.
Returns: 'T seq
A (lazy) sequence of the results of f.
Type parameters: 'Key, 'Value, 'T |
Map over keys and values of a dictionary.
|
Full Usage:
Dict.memoize f
Parameters:
'T -> 'U
-
The function to cache the results of. It is called once per distinct argument.
Returns: 'T -> 'U
A function that returns the cached result if it was called with the same argument before.
Type parameters: 'T, 'U (requires equality) |
Caches the results of a function in a Dictionary. The argument 'T is packed in a wrapper so it can be unit or null(=None) too. (A Dictionary would fail on a null as key ) The cache is not thread-safe, don't call the returned function from several threads at the same time.
|
Full Usage:
Dict.pop key dic
Parameters:
'Key
-
The key to remove.
dic : IDictionary<'Key, 'Value>
-
The dictionary to change.
Returns: 'Value
The value that was stored at the key.
Type parameters: 'Key, 'Value |
Get a value and remove the key and value from the dictionary, like *.pop() in Python. Throws a KeyNotFoundException if the key does not exist.
|
Full Usage:
Dict.set key value dic
Parameters:
'Key
-
The key to set.
value : 'Value
-
The value to set.
dic : IDictionary<'Key, 'Value>
-
The dictionary to change.
Type parameters: 'Key, 'Value |
Set value at key in a IDictionary, adds the key if it is missing.
Same as
|
Full Usage:
Dict.setIfKeyAbsent key value dic
Parameters:
'Key
-
The key to set.
value : 'Value
-
The value to set if the key is missing.
dic : IDictionary<'Key, 'Value>
-
The dictionary to change.
Returns: bool
true if the value was set, false if the key already existed and nothing was changed.
Type parameters: 'Key, 'Value |
Set value only if key does not exist yet.
Same as
|
Full Usage:
Dict.tryGet k dic
Parameters:
'Key
-
The key to look up.
dic : IDictionary<'Key, 'Value>
-
The dictionary to read from.
Returns: 'Value option
Some value if the key was found, None if not.
Type parameters: 'Key, 'Value |
Tries to get a value from a IDictionary.
|
Full Usage:
Dict.tryPop key dic
Parameters:
'Key
-
The key to remove.
dic : IDictionary<'Key, 'Value>
-
The dictionary to change.
Returns: 'Value option
Some value if the key was found, None if not.
Type parameters: 'Key, 'Value |
Tries to get a value and remove the key and value from the dictionary, like *.pop() in Python.
|
Full Usage:
Dict.values dic
Parameters:
IDictionary<'Key, 'Value>
-
The dictionary to read from.
Returns: 'Value seq
Type parameters: 'Key, 'Value |
Returns a (lazy) sequence of values.
|
Dicts