Hacker News new | ask | show | jobs
by qPkk4Bi 1085 days ago
How would I access anything locally created inside doSomeWork from my someCleanupFn in this example?
1 comments

Arguments to the doSomeWork can be carried through to someCleanupFn as can any return values from doSomeWork.

If doSomeWork returns all the pieces that need to be cleaned up by someCleanupFn (or those pieces are part of the original arguments), then those values can also be passed in as arguments to someCleanupFn.

This pattern (passing original arguments through, along with return values, to a supporting function) hints at a more elegant solution as well - a new monadic structure that supports this behavior by default.