Task 2 – Applicative functor
Imagine you have two functions wrapped in the Result
type: Result<Func<Tower, bool>, string> ValidateDamage
checks whether a tower’s damage is within acceptable limits, and Result<Func<Tower, bool>, string> ValidateName
checks whether the tower’s name meets certain criteria. Given a Result<Tower, string>
representing a single tower, use applicative functors to apply both validation functions to the tower, ensuring both validations pass:
public Result<Func<Tower, bool>, string> ValidateDamage = new Result<Func<Tower, bool>, string>(tower => tower.Damage < 100); public Result<Func<Tower, bool>, string> ValidateName = new Result<Func<Tower, bool>, string>(tower => tower.Name.Length > 5 && !tower.Name.Contains("BannedWord"));