Add Support for Async
Created versions of Map, Switch and Match that are awaitable, for references on netstandard 2.0 or greater than .Net 4.0
This would be a great addition to the library.
You guys know that this is already possible?
OneOf.OneOf<string, uint> test = 15;
var result = await test.Match(
async str => await Task.FromResult(str),
async i => await Task.FromResult(i.ToString()));
Instead of switch you can also use a Match, that just returns a Task.
await test.MapT#(async x => await ...) is what I was really hoping for. There doesn't appear to be support for it.
You guys know that this is already possible?
OneOf.OneOf<string, uint> test = 15; var result = await test.Match( async str => await Task.FromResult(str), async i => await Task.FromResult(i.ToString()));Instead of switch you can also use a Match, that just returns a
Task.
Yes. This should be possible with this PR.
Just a note as await Task.FromResult(str) would maybe result in a Task<Task
I guess what you meant was
var result = awai test.Match(
async str => await awaitableFunction(str), // with await
i => Task.FromResult(i.ToString())); // no await returning task
await test.MapT#(async x => await ...)is what I was really hoping for. There doesn't appear to be support for it.
Yes. I think this test is exactly that. https://github.com/mcintyre321/OneOf/pull/183/files#diff-bdd8be91f178aa5135c2b1ef3e22a9f1011430668103808b41d115d8a2e57658R42
var map1 = await input.MapT0Async(d => Task.FromResult(d.ToString(CultureInfo.InvariantCulture)));
In this case is not awaiting inside the lambda, but could be written as
var map1 = await input.MapT0Async(async d => await awaitableFunc(d));
Can you publish the version containing this feature to NuGet please? :-)