private IMonad<Option, Expression<Func<Address, bool>>> addressExpressionByContent(
IDictionary<string, Direction> sortedDirections, IDictionary<string, StreetType> sortedStreetTypes,
HansenAcctVw hansenAcctvW) {
var streetNameOption = hansenAcctvW.getStreetname(sortedDirections);
var houseNumberOption = hansenAcctvW.getHouseNumber();
var subdesignationOption = hansenAcctvW.getSubdesignation();
var postalCodeOption = hansenAcctvW.getFormattedPostalCode();
var predirectionOption = hansenAcctvW.getPredirection();
var postdirectionOption = hansenAcctvW.getPostdirection(sortedDirections);
var suffixOption = hansenAcctvW.getSuffix(sortedDirections, sortedStreetTypes);
var initialAddressExpressionOption = streetNameOption.bind(streetName =>
houseNumberOption.bind(houseNumber =>
suffixOption.map<Expression<Func<Address, bool>>>(suffix => address =>
address.CASTNAME == streetName &&
address.CASTNO == houseNumber &&
address.CASUFFIX == suffix)));
var predirectionLookup = predirectionOption.map<Expression<Func<Address, bool>>>(predirection =>
address => address.CAPREDIR == predirection).getValueOrDefault(() =>
address => address.CAPREDIR == null || address.CAPREDIR == " ");
var postdirectionLookup = postdirectionOption.map<Expression<Func<Address, bool>>>(postdirection =>
address => address.CAPOSTDIR == postdirection).getValueOrDefault(() =>
address => address.CAPOSTDIR == null || address.CAPOSTDIR == " ");
var subdesignationLookup = subdesignationOption.map<Expression<Func<Address, bool>>>(subdesignation =>
address => address.CASTSUB == subdesignation).getValueOrDefault(() =>
address => address.CASTSUB == null || address.CASTSUB == " ");
var postalCodeLookup = postalCodeOption.map<Expression<Func<Address, bool>>>(postalCode =>
address => address.CAPOSTCODE == postalCode).getValueOrDefault(() =>
address => address.CAPOSTCODE == null || address.CAPOSTCODE == " ");
Expression<Func<Address, bool>> cityLookup = address => address.CACITY == "REGINA";
Expression<Func<Address, bool>> addressType = address => address.CAADDRTYPE == "A";
Expression<Func<Address, bool>> addressKeyNot1 = address => address.ADDRKEY != 1;
var otherExpressionList = new [] {
predirectionLookup, postdirectionLookup, subdesignationLookup, postalCodeLookup, cityLookup,
addressType, addressKeyNot1
};
return initialAddressExpressionOption.map(initialAddressExpression => {
var foldedExpressionBody = otherExpressionList.Aggregate(initialAddressExpression.Body, (u, v) =>
Expression.AndAlso(u, v.Body));
return Expression.Lambda<Func<Address, bool>>(foldedExpressionBody, initialAddressExpression.Parameters[0]);
});
}