-
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Re: #15
An example for discussion:
public record Order
{
public int Id { get; set; }
public int InvoiceId { get; set; }
public Invoice? Invoice { get; set; }
}
public async Task<Maybe<Invoice?>> GetInvoiceForOrderAsync(int orderId)
{
var result = await _dbContext.Orders
.Where(x => x.Id == orderId)
.Select(x => new { x.Invoice })
.FirstOrDefaultAsync();
if (result is null)
{
return Maybe<Invoice?>.None;
}
return result.Invoice;
}Suppose a client wants to view the invoice for a recently placed order. It takes a while for invoices to be created, so the invoice may not exist. This service method tries to abstract this by supporting the following scenarios:
- The order does not exist. Expect
None. - The order does exist, but the invoice does not exist. Expect
Somewith anullvalue. - The order and invoice both exist. Expect
Somewith an instantiated value.
The problem is, EasyMonads does not currently work this way. The constructor for Maybe returns an instance in the None state if the provided value == null. Scenario 2 (above) is broken.
Metadata
Metadata
Assignees
Labels
No labels