rwskit.collections_ =================== .. py:module:: rwskit.collections_ .. autoapi-nested-parse:: Utilities for working with collections. Attributes ---------- .. autoapisummary:: rwskit.collections_.log Functions --------- .. autoapisummary:: rwskit.collections_.is_iterable rwskit.collections_.is_generator rwskit.collections_.get_first_non_null_value rwskit.collections_.recursive_sort rwskit.collections_.remove_none_from_dict Module Contents --------------- .. py:data:: log .. py:function:: is_iterable(obj: Any, consider_string_iterable: bool = False) -> bool Tests if the object is iterable. :param obj: An object. :type obj: any :param consider_string_iterable: Whether to consider strings iterable or not. :type consider_string_iterable: bool, default = False :returns: ``True`` if ``obj`` is iterable. :rtype: bool .. py:function:: is_generator(obj: Any) -> bool Checks if the object is a generator. :param obj: An object. :type obj: any :returns: ``True`` if the object is a generator. :rtype: bool .. py:function:: get_first_non_null_value(collection: Iterable) -> Optional[Any] 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``. :param collection: The collection to retrieve the value from. :type collection: Iterable :returns: The first non-null value in the series, if one exists, otherwise return ``None``. :rtype: Any, optional .. py:function:: recursive_sort(obj: Any) -> Any 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. :param obj: The input object :type obj: Any :returns: The returned object sorted. :rtype: Any .. py:function:: remove_none_from_dict(d: dict[str, Any]) -> dict[str, Any] Recursively remove ``None`` values from a (nested) dictionary.