These are chat archives for evhub/coconut

11th
Sep 2018
Brian Parma
@bj0
Sep 11 2018 06:54
is it possible to use async/await functions with the pipeline operators?
yggdr
@yggdr
Sep 11 2018 11:47
@bj0 Afaik no, only way I could make it work was rather ugly: await (await (x |> t1 ) |> t2) where t1 and t2 are coroutine functions.
Brian Parma
@bj0
Sep 11 2018 14:15
bummer, it would be pretty neat to be able to pipe directly to/from async queues and channels (aiochan). It would also be pretty neat to have async statement lambdas
yggdr
@yggdr
Sep 11 2018 17:09
@bj0 I hacked together a quick PoC of adding a new operator x |@> y defined as await y(x). It's available as the await-pipelines branch on my clone of the repo on github.
@evhub Maybe take a look at it and tell me what you think. The @ symbol was more or less spur of the moment (it's an "a" for async/await…). And while the implementation seems to work, I did not add an _coconut_await_pipe etc. to the header.py_templatesince I couldn't figure out what these functions are used for. In the compiled code of one of my projects, those functions seem to only be imported, but never used. What are they for?
Brian Parma
@bj0
Sep 11 2018 19:20
thats not bad, but doesn't cover as many cases as correctly parsing |> await y, and the ideal would be something like <some iter> |> map$(await q.put) or something like that, maybe |@> q could be short-hand for await q.put(...) is there a way to override |> for specific objects?
Evan Hubinger
@evhub
Sep 11 2018 19:44
@yggdr @bj0 I like the idea of an awaitable pipe operator, though I'm also not sold on the |@> syntax. I would much rather have something that actually uses the await keyword. Maybe open an issue for this? Also, the purpose of the _coconut_pipe functions is for operator functions like (|>).
Elliott Indiran
@eindiran
Sep 11 2018 21:08
@bj0 @yggdr Are there languages y'all know where you can use the pipe operator with await? I would be interested in seeing examples of how an existing implementation of that looks.
Brian Parma
@bj0
Sep 11 2018 21:15
the first thing that comes to mind is go's channel syntax
not that many languages I use have a pipe syntax
Brian Parma
@bj0
Sep 11 2018 23:42
my most recent experience is in kotlin. they don't have pipe notation, but they do have functional chaining with lambdas (list.filter { ... }.map { ... }), and it all supports coroutine suspention (though their flavor of coroutines are suspend/await by default)