gloe.collection¶
- class gloe.collection.Filter(filter_transformer)[source]¶
Bases:
Generic
[_T
],Transformer
[Iterable
[_T
],list
[_T
]]Transformer used to filter values in an iterable using other transformers instead of functions.
Example
In this example, we fetch a list of users and then filter the administrators.:
@transformer def is_admin(user: User) -> bool: ... get_admin_users: Transformer[Group, Iterable[User]] = ( get_users >> Filter(is_admin) )
- Parameters:
filter_transformer (Transformer[_T, bool]) – transformer applied to each item of the input iterable and check if this item must be dropped or not.
- class gloe.collection.FilterAsync(filter_transformer)[source]¶
Bases:
Generic
[_T
],AsyncTransformer
[Iterable
[_T
],list
[_T
]]Async transformer used to filter values in an iterable using other async transformers instead of functions.
Example
In this example, we fetch a list of users and then filter the administrators.:
@async_transformer async def check_is_admin(user: User) -> bool: ... get_admin_users: AsyncTransformer[Group, list[User]] = ( get_users >> FilterAsync(check_is_admin) )
- Parameters:
filter_transformer (AsyncTransformer[_T, bool]) – async transformer applied to each item of the input iterable
not. (and check if this item must be dropped or)
- class gloe.collection.Map(mapping_transformer)[source]¶
Bases:
Generic
[_T
,_U
],Transformer
[Iterable
[_T
],list
[_U
]]Transformer used to map values in an iterable using other transformers instead of functions.
Example
In this example, we fetch a list of users that belongs to a group. Then, we get the posts of each user and finally turn it into a single list of posts.:
@transformer def get_user_posts(user: User) -> list[Post]: ... get_posts_by_group: Transformer[Group, list[Post]] = ( get_users_by_group >> Map(get_user_posts) >> flatten )
- Parameters:
mapping_transformer (Transformer[_T, _U]) – transformer applied to each item of the input iterable the yield the mapped item of the output iterable.
- class gloe.collection.MapAsync(mapping_transformer)[source]¶
Bases:
Generic
[_T
,_U
],AsyncTransformer
[Iterable
[_T
],list
[_U
]]Transformer used to map values in an iterable using other async transformers instead of functions.
Example
In this example, we fetch a list of users that belongs to a group. Then, we get the posts of each user and finally turn it into a single list of posts.:
@async_transformer async def get_user_posts(user: User) -> list[Post]: ... get_posts_by_group: AsyncTransformer[Group, list[Post]] = ( get_users_by_group >> MapAsync(get_user_posts) >> flatten )
- Parameters:
mapping_transformer (AsyncTransformer[_T, _U]) – async transformer applied to each item of the input iterable the yield the mapped item of the output iterable.
- class gloe.collection.MapOver(iterable, mapping_transformer)[source]¶
Bases:
Generic
[_T
,_U
],Transformer
[_T
,list
[_U
]]- Parameters:
iterable (Iterable[_S])
mapping_transformer (Transformer[tuple[_T, _S], _U])
- class gloe.collection.MapOverAsync(iterable, mapping_transformer)[source]¶
Bases:
Generic
[_T
,_U
],AsyncTransformer
[_T
,list
[_U
]]- Parameters:
iterable (Iterable[_S])
mapping_transformer (AsyncTransformer[tuple[_T, _S], _U])