3 ms·
> Do most (or any) languages in which people take this approach actually enforce handling of all cases? In "most functional languages", your result would be a
by masklinn 6y ago
> Do most (or any) languages in which people take this approach actually enforce handling of all cases?
In "most functional languages", your result would be a sum type which requires dispatching explicitly between one case or the other, aka you wouldn't have a pair of conditionals instead you'd have something along the lines
switch (customerOrError) {
case IsCustomer(customer):
Console.WriteLine(customer.ID);
case IsError(errorMessage):
Console.WriteLine(errorMessage);
}
so from `customerOrError` you wouldn't have any sort of direct access to the customer or error, you must go through a dispatching construct.
In OO languages lacking sum types this sort of constructs would generally be implemented through lambdas or some sort of visitor e.g.
customerOrError.then(
customer => { Console.WriteLine(customer.Id); },
onError: errorMessage => { Console.WriteLine(errorMessage) }
);