Ask HN: How would you do this in Haskell?
The best answer I've come up with so far is, from that function, to return a tuple containing two values: the value the function returned before, and a Maybe. The Maybe contains Just String if the logging happened, and Nothing otherwise.
But then all functions from there to the end of the calculation have to be changed to return a tuple instead of just the results of the calculation. That doesn't sound like composablility.
Or, I could jam IO into the function where the data was to decide whether to do the logging, but that just feels wrong.
What's the idiomatic way to do something like this?