Sunday, August 9, 2015

have spooled Func expressions return a count?

I thought today of spooling up Actions in an observer pattern as described here and wondered if there would ever be any reason to use Funcs instead of Actions. (In C# a Func returns something while an Action is identical save that it returns void.) I guess you could return true as a Boolean example in a ceremonial display of, yes, this worked, or you could return the time for logging, though you could just get the time when logging too. In circling back to the first circumstance, what if you returned a number and the number came from a global variable which kept a count of how many Funcs had been run and this number was being incremented as each Func in the chain ran? (In a spool of Funcs the value returned is that of the last Func ran begging the question: What is the merit of a collection of concatenated Funcs?) Such a number could then be used to sanity check if the appropriate number of Func expressions ran. Of course, you could just pull this number from the global variable if you did the same thing with Actions instead of Funcs. Well, whatever. I suppose you could compare the global variable to the thing returned by the last Func as a sanity check. We are sort of back to the return value being ceremonial in this circumstance though.

No comments:

Post a Comment