I'm getting started with F# and async.
I have trying to convert some C# code that looks like:
public async Task<string> getValueOrDefault(string? key)
{
if (key is null)
{
return "default";
}
else
{
return await getValue(key);
}
}
My F# code looks like:
let getValueOrDefault (key: Option<string>) =
async {
return match key with
| None -> "default"
| Some (key) -> getValue key
}
It complains that the 2 branches have different types: string and Async<string>.
Changing return to return! of course tells me that "default" is expected to be Async<'a>
I can do:
let getValueOrDefault (key: Option<string>) =
async {
return! match key with
| None -> async { return "default" }
| Some (key) -> getValue key
}
But is this the "right" way of doing it? Does it matter?