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
Some with a null value.
- The order and invoice both exist. Expect
Some with 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.
Re: #15
An example for discussion:
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:
None.Somewith anullvalue.Somewith an instantiated value.The problem is, EasyMonads does not currently work this way. The constructor for
Maybereturns an instance in theNonestate if the provided value== null. Scenario 2 (above) is broken.