Search
- class search.Query(collection: Iterable[Any])[source]
Class to handle searching on objects using a LINQ-like format.
- all_(predicate: Callable[[Any], bool]) bool [source]
Determines whether all the elements of a sequence satisfy a condition.
- any_(predicate: Callable[[Any], bool]) bool [source]
Determines whether any of the elements of a sequence satisfy a condition.
- average() Any [source]
Calculates the average numeric value of the collection.
- Returns:
Average value of the collection, or None if the collection is empty.
- Return type:
Any
- concat(other: Iterable[Any]) Query [source]
Concatenates another iterable to the end of the current result set.
- Parameters:
other (Iterable[Any]) – Other iterable to include at the end of the current result set.
- Returns:
Query object
- Return type:
- contains(value: Any) bool [source]
Determines whether any of the elements of a sequence match the provided value.
- Parameters:
value (Any) – Value to compare against each element in the sequence.
- Returns:
True if any of the collection’s elements matches the value, otherwise False.
- Return type:
- count() int [source]
Retrieves the number of elements in the collection.
- Returns:
Number of elements in the collection.
- Return type:
- default_if_empty(default: Any) Any [source]
Returns each element in the collection, using the default if the collection is empty.
- Parameters:
default (Any) – Default value to use if the collection is empty.
- Returns:
Each element in the collection, or the default value.
- Return type:
Any
- distinct() Query [source]
Retrieve unique values from the sequence.
- Returns:
Query object
- Return type:
- element_at(index: int, default: Any | None = None) Any [source]
Retrieves the element at a specified index from the collection.
- Parameters:
index (int) – Index of the element to retrieve.
default (Any) – Default value to use if there’s not at element at that index.
- Returns:
Element at the specified index from the collection.
- Return type:
Any
- Exception:
IndexError when index is outside of collection and no default value is supplied.
- except_(except_values: Iterable[Any]) Query [source]
Exclude values from the result set.
- Parameters:
except_values (Iterable[Any]) – Values to exclude from the result set.
- Returns:
Query object
- Return type:
- first(default: Any | None = None) Any [source]
Retrieves the first element in the collection.
- Parameters:
default (Any) – Default value to use if the collection is empty.
- Returns:
First element in the collection.
- Return type:
Any
- Exception:
IndexError when collection is empty and no default value is supplied.
- group_by(key: Callable[[Any], Any], element: Callable[[Any], Any], result: Callable[[Any, Query], Any]) Query [source]
Groups elements by the provided key, and calls the result function for each key and element.
- intersect(intersect_values: Iterable[Any]) Query [source]
Only include values from intersect_values in the result set.
- Parameters:
intersect_values (Iterable[Any]) – Values to exclusively include in the result set.
- Returns:
Query object
- Return type:
- last(default: Any | None = None) Any [source]
Retrieves the last element in the collection.
- Parameters:
default (Any) – Default value to use if the collection is empty.
- Returns:
Last element in the collection.
- Return type:
Any
- Exception:
IndexError when collection is empty
- max_() Any [source]
Retrieves the maximum value of the elements in the collection.
- Returns:
Maximum value of the elements in the collection. Returns None on empty collection.
- Return type:
Any
- min_() Any [source]
Retrieves the minimum value of the elements in the collection.
- Returns:
Minimum value of the elements in the collection.
- Return type:
Any
- order_by(order_by: Callable[[Any], Any], descending: bool = False) Query [source]
Sorts the elements by one or more keys.
- reverse() Query [source]
Return the elements in the reverse order.
- Returns:
Query object
- Return type:
- select(selector: Callable[[Any, int], Any]) Query [source]
Performs a map on the elements in the collection based on the provided method.
- select_many(selector: Callable[[Any, int], Any]) Query [source]
Performs a map on the elements in the collection using the provided method, flattening iterables if applicable.
- single(default: Any | None = None) Any [source]
Retrieves a single value from the collection. An error will be thrown if there’s more than one value.
- Parameters:
default (Any) – Default value to use if the collection is empty.
- Returns:
Single value from the collection.
- Return type:
Any
- Exception:
IndexError on empty collection (if no default provided), InvalidOperationException if the collection has more than one element.
- skip_while(predicate: Callable[[Any], bool]) Query [source]
Skips elements while the predicate’s result for the element is True.
- sum_() int [source]
Retrieves the sum of the elements in the collection.
- Returns:
Sum of the elements in the collection.
- Return type:
- take_while(predicate: Callable[[Any], bool]) Query [source]
Takes elements while the predicate’s result for the element is True.
- to_list() list[Any] [source]
Gets the current query result as a list.
- Returns:
Current query result as a list.
- Return type:
list[Any]
- class search.SelectQueryAction(selector: Callable[[Any, int], Any], is_select_many: bool)[source]
Class for mapping elements in the collection based on the provided method.
- class search.WhereQueryAction(predicate: Callable[[Any], bool])[source]
Class for filtering elements in the collection based on the provided method.
- class search.ConcatQueryAction(other: Iterable[Any])[source]
Class for concatenating another collection at the end of the current one.
- class search.DistinctQueryAction[source]
Class for getting distinct values of elements in the collection.
- class search.ExceptQueryAction(exclude_values: Iterable[Any])[source]
Class for filtering out elements that are in a specified collection.
- class search.IntersectQueryAction(intersect_values: Iterable[Any])[source]
Class for only including elements that are in a specified collection.
- class search.UnionQueryAction(union_values: Iterable[Any])[source]
Class for doing a set union on the collection and specified values.
- class search.OrderByQueryAction(order_by: Callable[[Any], Any], descending: bool)[source]
Class for ordering results by an indicated key.
- class search.GroupByQueryAction(key: Callable[[Any], Any], element: Callable[[Any], Any], result: Callable[[Any, Query], Any])[source]
Class for grouping the collection by a provided key.
- class search.SkipQueryAction(skip_count: int)[source]
Class for skipping a certain number of elements.
- class search.SkipWhileQueryAction(predicate: Callable[[Any], bool])[source]
Class for skipping elements while a provided predicate is true.
- class search.TakeQueryAction(take_count: int)[source]
Class for taking a certain number of elements.