This is a follow-up to a question I asked earlier, but is (I think) much simpler, so I'm asking it separately. To clarify the question, I've stripped this one down even further.
The code here uses the Language-Ext
Nuget package.
The only data structure needed here is the following...
record Trans(int Id, decimal Amount)
I have a (very much simplified) method that calls an external service to approve a transaction...
static async Task<Either<int, string>> CallService(Trans transaction) =>
transaction.Amount < 1.5M
? "Success"
: -1;
I want to call this as part of code like this (again, very much simplified)...
static async Task<Either<int, string>> ApproveRefund(Trans transaction) =>
await (
from result in CallService(transaction).ToAsync()
select result
)
.Match(result => result, s => s);
However, I get a compiler error "Error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement" on the two lambdas I pass to the Match
method.
I can't work out what I've done wrong here. Anyone able to help? Thanks
I think you'd need to be more explicit with the return types...
.Match(Right<int, string>, Left<int, string>);
I'm not actually sure why you need to do this, but I have hit this issue occasionally, and this fixed it.
Maybe one of the experts can explain why, but that should get you going.