Reputation: 5954
Using delegates is there a benefit creating a dedicated variable instead of just using the function name?
This extract from a full code example is based upon the video: How FP Made Me Understand Design Patterns Better by Zoran Horvat.
public static PasswordPolicy AtLeast(int length) =>
input => input.Length >= length;
public static PasswordPolicy ContainsUpperLetter =>
input => input.Any(char.IsUpper);
PasswordPolicy minLengthPolicy = AtLeast(8);
PasswordPolicy upperLetterPolicy = ContainsUpperLetter;
PasswordPolicy combinedPolicy = minLengthPolicy // or AtLeast(8)
.And(ContainsUpperLetter) // or upperLetterPolicy
.And(specialCharPolicy);
If wonder if there is any difference or benefit in using minLengthPolicy and upperLetterPolicy
versus AtLeast(8) and ContainsUpperLetter
AtLeast(8)
// versus
minLengthPolicy
// and
.And(ContainsUpperLetter)
// versus
.And(upperLetterPolicy)
Since the syntax highlighting is not working 100% here a screenshot of netpad and a full code example for Netpad
Upvotes: 0
Views: 72