fumus.queries.query =================== .. py:module:: fumus.queries.query Classes ------- .. autoapisummary:: fumus.queries.query.Query Module Contents --------------- .. py:class:: Query(iterable) Bases: :py:obj:`fumus.queries.itertools_mixin.ItertoolsMixin` Abstraction over a sequence of elements supporting sequential aggregate operations .. py:attribute:: _iterable .. py:attribute:: _is_consumed :value: False .. py:attribute:: _on_close_handler :value: None .. py:method:: __iter__() .. py:method:: of(*iterable) :classmethod: Creates Query from args .. py:method:: of_nullable(iterable) :classmethod: Creates Query from args if iterable is not None; otherwise returns empty Query .. py:method:: empty() :classmethod: Creates empty Query .. py:method:: iterate(seed, operation, condition=None) :classmethod: Creates infinite ordered Query .. py:method:: generate(supplier) :classmethod: Creates infinite unordered Query with values generated by given supplier function .. py:method:: constant(element) :classmethod: Creates infinite Query with given value .. py:method:: from_range(*range_list: int) :classmethod: Creates Query from start (inclusive) to stop (exclusive) by an incremental step .. py:method:: _(range_obj: range) :classmethod: Creates Query range object .. py:property:: iterable .. py:method:: concat(*queries) Concatenates several queries together or adds new queries/collections to the current one .. py:method:: prepend(iterable) Prepends iterable to current query .. py:method:: filter(predicate) Filters values in query based on given predicate function .. py:method:: map(mapper) Returns a query consisting of the results of applying the given function to the elements of this query .. py:method:: filter_map(mapper, *, discard_falsy=False) Filters out all None or falsy values and applies mapper function to the elements of the query .. py:method:: flat_map(mapper) Maps each element of the query and yields the elements of the produced iterators .. py:method:: flatten() Converts a Query of multidimensional collection into a one-dimensional .. py:method:: peek(operation) Performs the provided operation on each element of the query without consuming it .. py:method:: distinct() Returns a query with the distinct elements of the current one .. py:method:: count() Returns the count of elements in the query .. py:method:: sum() Sums the elements of the query .. py:method:: average() Returns the average value of elements in the query .. py:method:: skip(count) Discards the first n elements of the query and returns a new query with the remaining ones .. py:method:: limit(count) Returns a query 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 query with the last n elements, or fewer if the underlying iterator ends sooner .. py:method:: take_while(predicate) Returns a query that yields elements based on a predicate .. py:method:: drop_while(predicate) Returns a query 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 query or a default value .. py:method:: take_last(default=None) Returns Optional with the last element of the query or a default value .. py:method:: sort(comparator=None, *, reverse=False) Sorts the elements of the current query 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 query in descending order. Alias for 'sort(comparator, reverse=True)' .. py:method:: find_first(predicate=None) Searches for an element of the query 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 query 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 query match the given predicate .. py:method:: all_match(predicate) Returns whether all elements of the query match the given predicate .. py:method:: none_match(predicate) Returns whether no elements of the query match the given predicate .. py:method:: min(comparator=None, default=None) Returns the minimum element of the query according to the given comparator .. py:method:: max(comparator=None, default=None) Returns the maximum element of the query according to the given comparator .. py:method:: for_each(operation) Performs an action for each element of this query .. py:method:: enumerate(start=0) Returns each element of the Query 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 query 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 query. In case of dict: The 'dict_collector' function receives an element from the query 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 Query, separated by the specified 'str_delimiter' .. py:method:: to_list() Returns a list of the elements of the current query .. py:method:: to_tuple() Returns a tuple of the elements of the current query .. py:method:: to_set() Returns a set of the elements of the current query .. py:method:: to_dict(collector=None, merger=None) Returns a dict of the elements of the current query. The 'collector' function receives an element from the query 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 Query, separated by the specified delimiter .. py:method:: group_by(classifier=None, collector=None) Performs a "group by" operation on the elements of the query 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 query, causing the provided close handler to be called .. py:method:: on_close(handler) Returns an equivalent query with an additional close handler .. py:method:: __repr__() .. py:method:: _join(delimiter=', ') .. py:method:: take_nth(idx, default=None) Returns Optional with the nth element of the query or a default value .. py:method:: all_equal(key=None) Returns True if all elements of the query are equal to each other