by shortrounddev2 · 1y ago · 0 comments
In F#
let Foo =
async {
let! data = getData() |> Async.AwaitTask
return data.value
}
Is this the best they can do? C# just has async Task<Data> Foo() =>
(await getData()).value;
Ive always wanted ML syntax like this: let async Foo =
let data = await getData
data.value
I just dont write a ton of pure functions which have no I/O dependencies let Foo () = getData() |> Task.map _.value
And it'll be easier to work with the .NET ecosystem if you use the task computation expression[1] over the async one.[0]: https://github.com/demystifyfp/FsToolkit.ErrorHandling
[1]: https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
let foo = task {
let! data = getData()
return data.value
}
In F#, you interoperate with Task<T> transparently, and there is a number of community libraries to further enhance the experience. It also supports nice combinators like and! out of box.