Closed slimshader closed 3 days ago
If you haven't started using the *Async
variants yet, then you may want to skip them and go straight to v5
. The proposal to remove the *Async
variants has been acted upon and they don't exist any more.
If you want to continue with OptionAsync
on v4
then you use LINQ, not async/await:
static OptionAsync<int> GetIntAsync() =>
from _ in SomeAsync(wait(1))
select 42;
static async Task<Unit> wait(int seconds)
{
await Task.Delay(TimeSpan.FromSeconds(1));
return unit;
}
So, all of the standard functional operators (Map
, Bind
, Apply
, etc.) understand the asynchrony and apply it as part of their implementations.
In version 5 you'd use the IO
monad (support for async essentially) with other monad-transformers:
static OptionT<IO, int> GetIntAsync() =>
from _ in wait(1)
select 42;
static IO<Unit> wait(int seconds) =>
liftIO(async e => await Task.Delay(TimeSpan.FromSeconds(1), e.Token));
The benefit of the new approach is:
wait
aboveIO
can be pared with any other monad transformer: OptionT
, TryT
, ValidationT
, StreamT
, RWST
, Proxy
(part of pipes), etc. So, whereas v4
only has OptionAsync
, EitherAsync
, and TryAsync
; v5
can support asynchrony everywhere.
Hi,
I trying to wrap my head around synchrony with LangExt but I am stuck on the simplest thing: I'd like my services like IFileDownlaoder to return OptionAsync<byte[]> instead of Task<Option<byte[]>> but implantation as simple as
fails to compile with error:
Indeed, when looking upon implementations OptionAsync nor EitherAsync implement custom awaitables and related async machinery.
So: what the return types of async methods should be so that functional pipelines could be built from LangExt types?