I mean, it's not a stretch to see how you can use native pattern matching with ErrorOr result types.
#!/usr/local/share/dotnet/dotnet run
#:package ErrorOr@2.0.1
using ErrorOr;
var computeRiskFactor = ErrorOr<decimal> ()
=> 0.5m; // Just an example
var applyAdjustments = ErrorOr<decimal> (decimal baseRiskFactor)
=> baseRiskFactor + 0.1m; // Just an example
var approvalDecision = computeRiskFactor()
.Then(applyAdjustments)
.Match(
riskFactor => riskFactor switch {
< 0.5m => "Approved",
< 0.75m and >= 0.5m => "Approved with Conditions",
>= 0.75m and < 0.9m => "Manual Review",
_ => "Declined"
},
errors => "Error computing risk factor"
);
Console.WriteLine($"Loan application: {approvalDecision}");
(Fully contained program, BTW)Here's the OCaml version:
let compute_risk_factor () = 0.5
let apply_adjustments base_risk_factor = base_risk_factor +. 0.1
let approval_decision =
let risk_factor = compute_risk_factor () |> apply_adjustments in
match risk_factor with
| r when r < 0.5 -> "Approved"
| r when r < 0.75 -> "Approved with Conditions"
| r when r < 0.9 -> "Manual Review"
| _ -> "Declined"
let () =
print_endline approval_decision
Still not functional enough?...Or you just don't like C#? No point moving goal posts.