I have the following working code:
var cached = Cache.Get(object);
var load = (cached.HasValue)
? cached.Value()
: await GetLoad(object);
Is it possible to make that into an extension? I've tried the following:
public async static Task<T> Else<T>(this Result<T> result, Task<T> fn)
{
if (result.HasValue)
{
return result.Value;
}
return await fn;
}
// Called like this:
var cached = Cache.Get(object).Else(GetLoad(object));
But the problem is it ALWAYS calls the GetLoad(object) regardless of the condition being met or not.
What I need is for the GetLoad(object) to ONLY be called if result.HasValue is false.
Thanks in advance!