Home Assistant Unofficial Reference 2024.12.1
homeassistant.util.collection Namespace Reference

Functions

Iterable[Any] chunked (Iterable iterable, int chunked_num)
 
Iterable[Any] chunked_or_all (Collection[Any] iterable, int chunked_num)
 
list[Any] take (int take_num, Iterable iterable)
 

Detailed Description

Helpers for working with collections.

Function Documentation

◆ chunked()

Iterable[Any] homeassistant.util.collection.chunked ( Iterable  iterable,
int  chunked_num 
)
Break *iterable* into lists of length *n*.

From more-itertools

Definition at line 17 of file collection.py.

◆ chunked_or_all()

Iterable[Any] homeassistant.util.collection.chunked_or_all ( Collection[Any]  iterable,
int  chunked_num 
)
Break *collection* into iterables of length *n*.

Returns the collection if its length is less than *n*.

Unlike chunked, this function requires a collection so it can
determine the length of the collection and return the collection
if it is less than *n*.

Definition at line 25 of file collection.py.

◆ take()

list[Any] homeassistant.util.collection.take ( int  take_num,
Iterable  iterable 
)
Return first n items of the iterable as a list.

From itertools recipes

Definition at line 9 of file collection.py.