-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow pipe into await
#727
Comments
Notably this is easily definable manually as async def acall(f, awaitable) = f(await awaitable) and adding this to We could alternatively add |
More general async def acall(f, /, *args, **kwargs) =
f(*(await x for x in args), **{k: await v for k, v in kwargs.items()}) Alternatively, we could also do this more like data alift(f):
async def __call__(self, *args, **kwargs) =
self.f(*(await x for x in args), **{k: await v for k, v in kwargs.items()}) |
New proposed built-in: async def async_bind(f, /, *args, **kwargs):
out = f(*(await x for x in args), **{k: await v for k, v in kwargs.items()})
if hasattr(got, "__await__"):
out = await out
return out Maybe we should also allow inputs to be non-awaitables too? |
Here's another alternative here: an (
get_data()
|> async_func
|await> non_async_func
) Some documentation: (|await>) => await pipe forward
(|await*>) => await multi-arg pipe forward
(|await**>) => await keyword arg pipe forward
(<await|) => await pipe backward
(<*await|) => await multi-arg pipe backward
(<**await|) => await keyword arg pipe backward
(|await?>) => await None-aware pipe forward
(|await?*>) => await None-aware multi-arg pipe forward
(|await?**>) => await None-aware keyword arg pipe forward
(<?await|) => await None-aware pipe backward
(<*?await|) => await None-aware multi-arg pipe backward
(<**?await|) => await None-aware keyword arg pipe backward The |
The problem with the |
Maybe we should just add some sort of special syntax that makes it clear that this really only works in pipes? Something like: (
get_data()
|> async_func
|> await
|> non_async_func
)
Also, notably, what neither this nor the pipe syntax do, but the built-ins do accomplish, is let you work with awaitables in non-async contexts. |
Nice timing, I wanted to start a discussion about async pipes as well because I recently found an old implementation of mine, back from 1.x times :) Now what surprises me a little is the semantics you seem to want for How would you want a starpipe to work? Does
compile to
(which is how I read your proposal) or
? I would expect/want the second version. What would most people expect or want this
to compile to? I can see why people might see the await in there as sort of a marker, like "do the pipe thing until here, then await the result, then continue the piping with the result from the awaiting". I would however argue that that functionality (if desired) should go to a separate syntax, like the edit |
Yeah, the |
The pipe into |
I like the (edit b/c of accidental send) |
After a bit of testing I just realised that |
What sort of use case are you imagining here that you would want |
Adding
fmap
support for awaitables would allow writinginstead of having to write
The text was updated successfully, but these errors were encountered: