rwskit.collections
Utilities for working with collections.
Attributes
Functions
|
Tests if the object is iterable. |
|
Checks if the object is a generator. |
|
Recursively try to get the first non-null value in a collection. |
|
Attempts to sort an object recursively according to the following rules: |
|
Recursively remove |
Module Contents
- rwskit.collections_.is_iterable(obj: Any, consider_string_iterable: bool = False) bool[source]
Tests if the object is iterable.
- Parameters:
obj (any) – An object.
consider_string_iterable (bool, default = False) – Whether to consider strings iterable or not.
- Returns:
Trueifobjis iterable.- Return type:
bool
- rwskit.collections_.is_generator(obj: Any) bool[source]
Checks if the object is a generator.
- Parameters:
obj (any) – An object.
- Returns:
Trueif the object is a generator.- Return type:
bool
- rwskit.collections_.get_first_non_null_value(collection: Iterable) Any | None[source]
Recursively try to get the first non-null value in a collection.
This method will recursively traverse the collection until it finds a non-iterable value that is not
None.- Parameters:
collection (Iterable) – The collection to retrieve the value from.
- Returns:
The first non-null value in the series, if one exists, otherwise return
None.- Return type:
Any, optional
- rwskit.collections_.recursive_sort(obj: Any) Any[source]
Attempts to sort an object recursively according to the following rules:
If the object is a dictionary, it will be sorted by its keys and its values will be sorted recursively.
If the object is a list or tuple, it will be sorted by its values. Typically, a value is a primitive, but lists, tuples, and dictionaries are also valid. In these cases, the collections are compared after sorting.
Any other value is returned unchanged.
- Parameters:
obj (Any) – The input object
- Returns:
The returned object sorted.
- Return type:
Any