pfun.dict.Dict
dataclass
Immutable dictionary class with functional helper methods
__contains__(self, key)
special
Test if key
is a key in this dictionary
Examples:
1 2 |
|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
object |
The key to test for membership |
required |
Returns:
Type | Description |
---|---|
bool |
|
__eq__(self, other)
special
Compare self
with other
Returns:
Type | Description |
---|---|
bool |
|
__getitem__(self, key)
special
get the value associated with a key
Examples:
1 2 |
|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
~K |
the key to retrieve |
required |
Return |
|
required |
__init__(self, d={})
special
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d |
Mapping[~K, ~V] |
|
{} |
__iter__(self)
special
Get an iterator over the keys in this dictionary
Examples:
1 2 |
|
Returns:
Type | Description |
---|---|
Iterator[~K] |
Iterator of the keys in this dictionary |
__len__(self)
special
Get the number of key/value pairs in this dictionary
Examples:
1 2 |
|
Returns:
Type | Description |
---|---|
int |
Number of key/value pairs in this dictionary |
copy(self)
Get a shallow copy of this dictionary.
Examples:
1 2 |
|
Returns:
Type | Description |
---|---|
Dict[K, V] |
Copy of this dict |
get(self, key)
get the value associated with a key
Examples:
1 2 3 4 |
|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
~K |
the key to retrieve |
required |
default |
|
value to return if the key is not found |
required |
Returns:
Type | Description |
---|---|
Union[pfun.maybe.Nothing, pfun.maybe.Just[~V]] |
|
items(self)
Get the keys and values of this dictionary
Examples:
1 2 |
|
Returns:
Type | Description |
---|---|
ItemsView[~K, ~V] |
Keys and values of this dictionary |
keys(self)
Get the keys in this dictionary
Examples:
1 2 |
|
Returns:
Type | Description |
---|---|
KeysView[~K] |
Dictionary keys |
set(self, key, value)
Combine keys and values from this dictionary with a new dictionary that includes key and value
Examples:
1 2 |
|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
~K |
key to add to the new dictionary |
required |
value |
~V |
value to associate with key |
required |
Returns:
Type | Description |
---|---|
Dict[K, V] |
new dictionary with existing keys and values in addition to key and value |
update(self, other)
Get a copy of this dictionary updated with key/value pairs
from other
Examples:
1 2 |
|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Union[Mapping[~K, ~V], Dict[K, V]] |
Dict to add to keys/values of this dictionary |
required |
Returns:
Type | Description |
---|---|
Dict[K, V] |
copy of |
values(self)
Get the values in this dictionary
Examples:
1 2 |
|
Returns:
Type | Description |
---|---|
ValuesView[~V] |
Dictionary values |
without(self, key)
Get a copy of this dictionary without
the mapping associated with key
.
Examples:
1 2 |
|
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
~K |
The |
required |
Returns:
Type | Description |
---|---|
Dict[K, V] |
Copy of this dictionary without |