Hi, in chapter 3, why function purity matters, under 3.4.2 Testability without so much boilerplat,
under INJECTING FUNCTIONS AS DEPENDENCIES, the sample code below is one of the solution to ensure the validator function become testable.
However, can i clarify that this function although become testable, it is still not considered pure function?
Cos if i repeatedly call the same DateNotPastValidator function with the same Clock argument (which internally get the current date time), the DateNotPastValidator function might return different arguments, hence breaking one of the rule of pure function. Pure function which calls an impure function (in this case, the Clock function) is itself become impure.
public record DateNotPastValidator(Func<DataTime> Clock):IValidator<MakerTransfer>{
public bool IsValid(MakerTransfer transfer)=>Clock().Date<= Transfer.Date.Date
}
Hence my query is
- Is my above understanding correct about it being impure?
- if my understanding is correct, is there a way to make it testable and at same time pure?
Hi, in chapter 3, why function purity matters, under 3.4.2 Testability without so much boilerplat,
under INJECTING FUNCTIONS AS DEPENDENCIES, the sample code below is one of the solution to ensure the validator function become testable.
However, can i clarify that this function although become testable, it is still not considered pure function?
Cos if i repeatedly call the same DateNotPastValidator function with the same Clock argument (which internally get the current date time), the DateNotPastValidator function might return different arguments, hence breaking one of the rule of pure function. Pure function which calls an impure function (in this case, the Clock function) is itself become impure.
Hence my query is