pyrio.streams ============= .. py:module:: pyrio.streams Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/pyrio/streams/base_stream/index /autoapi/pyrio/streams/file_stream/index /autoapi/pyrio/streams/stream/index Classes ------- .. autoapisummary:: pyrio.streams.BaseStream pyrio.streams.FileStream Package Contents ---------------- .. py:class:: BaseStream(iterable) Base class for Stream objects; describes core supported operations .. py:attribute:: _iterable .. py:attribute:: _is_consumed :value: False .. py:attribute:: _on_close_handler :value: None .. py:method:: __iter__() .. py:property:: iterable .. py:method:: concat(*streams) Concatenates several streams together or adds new streams/collections to the current one .. py:method:: prepend(iterable) Prepends iterable to current stream .. py:method:: filter(predicate) Filters values in stream based on given predicate function .. py:method:: map(mapper) Returns a stream consisting of the results of applying the given function to the elements of this stream .. py:method:: filter_map(mapper, *, discard_falsy=False) Filters out all None or falsy values and applies mapper function to the elements of the stream .. py:method:: flat_map(mapper) Maps each element of the stream and yields the elements of the produced iterators .. py:method:: flatten() Converts a Stream of multidimensional collection into a one-dimensional .. py:method:: peek(operation) Performs the provided operation on each element of the stream without consuming it .. py:method:: distinct() Returns a stream with the distinct elements of the current one .. py:method:: count() Returns the count of elements in the stream .. py:method:: _validate_numeric_data(op) .. py:method:: sum() Sums the elements of the stream .. py:method:: average() Returns the average value of elements in the stream .. py:method:: skip(count) Discards the first n elements of the stream and returns a new stream with the remaining ones .. py:method:: limit(count) Returns a stream with the first n elements, or fewer if the underlying iterator ends sooner .. py:method:: head(count) Alias for 'limit' .. py:method:: tail(count) Returns a stream with the last n elements, or fewer if the underlying iterator ends sooner .. py:method:: take_while(predicate) Returns a stream that yields elements based on a predicate .. py:method:: drop_while(predicate) Returns a stream that skips elements based on a predicate and yields the remaining ones .. py:method:: take_first(default=None) Returns Optional with the first element of the stream or a default value .. py:method:: take_last(default=None) Returns Optional with the last element of the stream or a default value .. py:method:: sort(comparator=None, *, reverse=False) Sorts the elements of the current stream according to natural order or based on the given comparator. If 'reverse' flag is True, the elements are sorted in descending order .. py:method:: reverse(comparator=None) Sorts the elements of the current stream in descending order. Alias for 'sort(comparator, reverse=True)' .. py:method:: find_first(predicate=None) Searches for an element of the stream that satisfies a predicate. Returns an Optional with the first found value, if any, or None .. py:method:: find_any(predicate=None) Searches for an element of the stream that satisfies a predicate. Returns an Optional with some of the found values, if any, or None .. py:method:: any_match(predicate) Returns whether any elements of the stream match the given predicate .. py:method:: all_match(predicate) Returns whether all elements of the stream match the given predicate .. py:method:: none_match(predicate) Returns whether no elements of the stream match the given predicate .. py:method:: min(comparator=None, default=None) Returns the minimum element of the stream according to the given comparator .. py:method:: max(comparator=None, default=None) Returns the maximum element of the stream according to the given comparator .. py:method:: for_each(operation) Performs an action for each element of this stream .. py:method:: enumerate(start=0) Returns each element of the Stream preceded by his corresponding index (by default starting from 0 if not specified otherwise) .. py:method:: reduce(accumulator, identity=None) Reduces the elements to a single one, by repeatedly applying a reducing operation. Returns Optional with the result, if any, or None .. py:method:: compare_with(other, comparator=None) Compares current stream with another one based on a given comparator .. py:method:: collect(collection_type, dict_collector=None, dict_merger=None, str_delimiter=', ') Returns a collection from the stream. In case of dict: The 'dict_collector' function receives an element from the stream and returns a (key, value) pair or a DictItem specifying how the dict should be constructed. The 'dict_merger' functions indicates in the case of a collision (duplicate keys), which entry should be kept. E.g. lambda old, new: new In case of str: Concatenates the elements of the Stream, separated by the specified 'str_delimiter' .. py:method:: to_list() Returns a list of the elements of the current stream .. py:method:: to_tuple() Returns a tuple of the elements of the current stream .. py:method:: to_set() Returns a set of the elements of the current stream .. py:method:: to_dict(collector=None, merger=None) Returns a dict of the elements of the current stream. The 'collector' function receives an element from the stream and returns a (key, value) pair or a DictItem specifying how the dict should be constructed. The 'merger' functions indicates in the case of a collision (duplicate keys), which entry should be kept. E.g. lambda old, new: new .. py:method:: _unpack_dict_item(item) .. py:method:: to_string(delimiter=', ') Concatenates the elements of the Stream, separated by the specified delimiter .. py:method:: group_by(classifier=None, collector=None) Performs a "group by" operation on the elements of the stream according to a classification function. Returns the results in a dict built using collector function (optionally provided by the user or via a default one) .. py:method:: _group_by(classifier=None) .. py:method:: quantify(predicate=bool) Count how many of the elements are Truthy or evaluate to True based on a given predicate .. py:method:: close() Closes the stream, causing the provided close handler to be called .. py:method:: on_close(handler) Returns an equivalent stream with an additional close handler .. py:method:: __repr__() .. py:method:: _join(delimiter=', ') .. py:class:: FileStream(file_path) Bases: :py:obj:`pyrio.streams.BaseStream` Derived Stream class for querying files; maps file content to im-memory dict structures and vice versa .. py:method:: process(file_path, *, f_open_options=None, f_read_options=None, **kwargs) :classmethod: Creates Stream from a file with advanced 'reading' options passed by the user .. py:method:: _read_file(file_path, f_open_options=None, f_read_options=None, **kwargs) :classmethod: .. py:method:: _read_dsv(path, f_open_options, f_read_options) :staticmethod: .. py:method:: _read_mapping(path, f_open_options, f_read_options, **kwargs) :staticmethod: .. py:method:: _read_plain(path, f_open_options) :staticmethod: .. py:method:: save(file_path=None, *, f_open_options=None, f_write_options=None, null_handler=None, **kwargs) Writes Stream to a new file (or updates an existing one) with advanced 'writing' options passed by the user .. py:method:: _write_dsv(path, tmp_path, f_open_options, f_write_options, null_handler=None) .. py:method:: _write_mapping(path, tmp_path, f_open_options, f_write_options, null_handler=None, **kwargs) .. py:method:: _write_plain(path, tmp_path, f_open_options, f_write_options) .. py:method:: _get_file_path(file_path, read_mode=True) :staticmethod: .. py:method:: _prepare_file_paths(file_path) .. py:method:: _prepare_io_options(settings) :staticmethod: .. py:method:: _atomic_write(path, tmp_path, f_open_options)