Skip to content

Is DateNotPastValidator still considered pure function, although it has been revamped to become testable #15

Description

@hannah23280

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

  1. Is my above understanding correct about it being impure?
  2. if my understanding is correct, is there a way to make it testable and at same time pure?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions