Skip to main content
6 events
when toggle format what by license comment
Dec 21, 2019 at 16:37 vote accept pob
Sep 14, 2019 at 16:09 comment added Doc Brown @pob: I still don't get it - my suggestions contains two functions, find-config-path contains only the decision logic, and .getParentFile does the content reading. As an alternative, you could make find-config-path a function which operates on a lazy sequence of strings, and implement a second function which produces those strings from path as its parent folder names. Then you can pass the sequence into find-config-path as a parameter. But don't expect the code to look very different from the solution above.
Sep 14, 2019 at 13:21 comment added pob You're missing nothing, you are correct in that the test function will be pure. I realized I didn't ask the right question. What I was looking for is for an approach that would leave me (perhaps) with two functions in the "production code", one pure and another one isolating the side-effects. For example, if I would like to search the configuration file only in one directory, I would have have one function for reading the contents of that directory, and a second one with the decision logic. I would only need to test the second one without the need for additional mocks.
Sep 14, 2019 at 12:04 comment added Doc Brown @pob: if there is a way to decouple the decision making (as a pure function) from the side-effects (I/O) - can you explain in what way my suggestion does not exactly provide this? You now can pass a side-effect free mock function for gpf, which provides some dummy parent files/folders without doing any real I/O. What am I missing here?
Sep 14, 2019 at 11:57 comment added pob Thank you, I have considered something along those lines. In fact, I could treat the path itself as an "object" that could be mocked. What I am wondering is if there is a way to decouple the decision making (as a pure function) from the side-effects (I/O).
Sep 14, 2019 at 10:52 history answered Doc Brown CC BY-SA 4.0