As noted in #2491, the function docstring does not sufficiently explain its difference to forEach and in what circumstances one should use it. The module docstring gives more details, but is still misleading: it does not even mention the, I believe, main property of the function, f being applied at most once to each (structurally equal) subexpression. Thus a much more relevant question as to whether the function should be used might be whether f is much more expensive than p plus expr hashing.
Thus I propose to first confirm and document the intent of the function as well as consider renaming it (such as to forEachOnceWhere) before considering any refactors on top of it.
As noted in #2491, the function docstring does not sufficiently explain its difference to
forEachand in what circumstances one should use it. The module docstring gives more details, but is still misleading: it does not even mention the, I believe, main property of the function,fbeing applied at most once to each (structurally equal) subexpression. Thus a much more relevant question as to whether the function should be used might be whetherfis much more expensive thanpplus expr hashing.Thus I propose to first confirm and document the intent of the function as well as consider renaming it (such as to
forEachOnceWhere) before considering any refactors on top of it.