I've been dabbling with functional programming for a little bit and I'm trying to get my head around partial application and currying.
I'm looking for some insight on how I can apply partial application and currying to the functions below:
var Page_Validators = [{
"controltovalidate": "Content_C002_txtAddress",
"focusOnError": "t",
"errormessage": "No Address Entered",
"display": "Dynamic",
"validationGroup": "ProfileControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_txtCity",
"focusOnError": "t",
"errormessage": "No City Entered",
"display": "Dynamic",
"validationGroup": "ProfileControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_drpState",
"focusOnError": "t",
"errormessage": "State Required",
"display": "Dynamic",
"validationGroup": "ProfileControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_txtZipcode",
"focusOnError": "t",
"errormessage": "No Zipcode Entered",
"display": "Dynamic",
"validationGroup": "ProfileControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_phoneNumberFull",
"focusOnError": "t",
"errormessage": "Missing Phone Number",
"display": "Dynamic",
"validationGroup": "ProfileControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_txtSupFullName",
"focusOnError": "t",
"errormessage": "No Name Entered",
"display": "Dynamic",
"validationGroup": "SupervisorControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_txtSupTitle",
"focusOnError": "t",
"errormessage": "No Title Entered",
"display": "Dynamic",
"validationGroup": "SupervisorControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_txtSupPhoneFull",
"focusOnError": "t",
"errormessage": "Missing Phone Number",
"display": "Dynamic",
"validationGroup": "SupervisorControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_txtSupEmail",
"focusOnError": "t",
"errormessage": "No Email Entered",
"display": "Dynamic",
"validationGroup": "SupervisorControl",
"initialvalue": "",
"isvalid": true
}, {
"controltovalidate": "Content_C002_SignatureField",
"focusOnError": "t",
"errormessage": "Signature Required",
"display": "Dynamic",
"validationGroup": "ProfileControl",
"initialvalue": "",
"isvalid": true
}];
function filterArrayBy(arr, searchString) {
return arr.filter(key => key.controltovalidate.toLowerCase().includes(searchString.toLowerCase()));
}
function toggleValidatorsState(arr, condtion) {
return arr.map(el => ValidatorEnable(el, condition));
}
const supervisorValidators = filterArrayBy(Page_Validators, "txtSup");
const disabledValidators = toggleValidatorsState(supervisorValidators, true);
console.log(disabledValidators);
ASIDE
The toggleValidatorState function is invoking an ASP.NET function so the code snippet will not function (unless you have asp.net)
Except for the ASP.NET function can these functions be simplified or make use of partial application with currying??
I feel like I'm repeating myself by having to pass an array into the two functions.
I've been looking into using Lodash or Ramda but could I achieve the same without the use of an external library.