pyrio.streams.base_stream
Classes
Base class for Stream objects; describes core supported operations |
Module Contents
- class pyrio.streams.base_stream.BaseStream(iterable)
Base class for Stream objects; describes core supported operations
- _iterable
- _is_consumed = False
- _on_close_handler = None
- __iter__()
- property iterable
- concat(*streams)
Concatenates several streams together or adds new streams/collections to the current one
- prepend(iterable)
Prepends iterable to current stream
- filter(predicate)
Filters values in stream based on given predicate function
- map(mapper)
Returns a stream consisting of the results of applying the given function to the elements of this stream
- filter_map(mapper, *, discard_falsy=False)
Filters out all None or falsy values and applies mapper function to the elements of the stream
- flat_map(mapper)
Maps each element of the stream and yields the elements of the produced iterators
- flatten()
Converts a Stream of multidimensional collection into a one-dimensional
- peek(operation)
Performs the provided operation on each element of the stream without consuming it
- distinct()
Returns a stream with the distinct elements of the current one
- count()
Returns the count of elements in the stream
- _validate_numeric_data(op)
- sum()
Sums the elements of the stream
- average()
Returns the average value of elements in the stream
- skip(count)
Discards the first n elements of the stream and returns a new stream with the remaining ones
- limit(count)
Returns a stream with the first n elements, or fewer if the underlying iterator ends sooner
- head(count)
Alias for ‘limit’
- tail(count)
Returns a stream with the last n elements, or fewer if the underlying iterator ends sooner
- take_while(predicate)
Returns a stream that yields elements based on a predicate
- drop_while(predicate)
Returns a stream that skips elements based on a predicate and yields the remaining ones
- take_first(default=None)
Returns Optional with the first element of the stream or a default value
- take_last(default=None)
Returns Optional with the last element of the stream or a default value
- 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
- reverse(comparator=None)
Sorts the elements of the current stream in descending order. Alias for ‘sort(comparator, reverse=True)’
- 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
- 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
- any_match(predicate)
Returns whether any elements of the stream match the given predicate
- all_match(predicate)
Returns whether all elements of the stream match the given predicate
- none_match(predicate)
Returns whether no elements of the stream match the given predicate
- min(comparator=None, default=None)
Returns the minimum element of the stream according to the given comparator
- max(comparator=None, default=None)
Returns the maximum element of the stream according to the given comparator
- for_each(operation)
Performs an action for each element of this stream
- enumerate(start=0)
Returns each element of the Stream preceded by his corresponding index (by default starting from 0 if not specified otherwise)
- 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
- compare_with(other, comparator=None)
Compares current stream with another one based on a given comparator
- 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’
- to_list()
Returns a list of the elements of the current stream
- to_tuple()
Returns a tuple of the elements of the current stream
- to_set()
Returns a set of the elements of the current stream
- 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
- _unpack_dict_item(item)
- to_string(delimiter=', ')
Concatenates the elements of the Stream, separated by the specified delimiter
- 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)
- _group_by(classifier=None)
- quantify(predicate=bool)
Count how many of the elements are Truthy or evaluate to True based on a given predicate
- close()
Closes the stream, causing the provided close handler to be called
- on_close(handler)
Returns an equivalent stream with an additional close handler
- __repr__()
- _join(delimiter=', ')