1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 03:24:20 +00:00

Add AsyncLambda

This commit is contained in:
Steffo 2021-04-17 15:51:12 +02:00
parent 33b04f2a0a
commit 3754f5cca7
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -304,6 +304,21 @@ class Check(CheckBase):
return self.error return self.error
class AsyncLambda(Wrench):
"""
Apply an asyncronous function over the received objects.
"""
def __init__(self, func: t.Callable[[t.Any], t.Awaitable[t.Any]]):
self.func: t.Callable[[t.Any], t.Awaitable[t.Any]] = func
"""
The function to apply.
"""
async def filter(self, obj: t.Any) -> t.Any:
return await self.func(obj)
__all__ = ( __all__ = (
"Check", "Check",
"CheckBase", "CheckBase",
@ -318,4 +333,5 @@ __all__ = (
"Type", "Type",
"Wrench", "Wrench",
"WrenchException", "WrenchException",
"AsyncLambda",
) )