mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 03:24:20 +00:00
✨ Add AsyncLambda
This commit is contained in:
parent
33b04f2a0a
commit
3754f5cca7
1 changed files with 16 additions and 0 deletions
|
@ -304,6 +304,21 @@ class Check(CheckBase):
|
|||
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__ = (
|
||||
"Check",
|
||||
"CheckBase",
|
||||
|
@ -318,4 +333,5 @@ __all__ = (
|
|||
"Type",
|
||||
"Wrench",
|
||||
"WrenchException",
|
||||
"AsyncLambda",
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue