I stumbled across this which contains a neat pattern I could currently use. However I’m getting type error [M0077], a shared function is only allowed as a public field of an actor (This is a limitation of the current version.) at compile.
This is returning an anonymous shared function that closes over some local data.
Yeah, it’s unlikely we will support that any time soon, though its actually related to the discussion on thunks here. We would need both private entry points (not supported by the IC) and, ideally, unforgeable closures as candid values.
Curiously, this is related to @rossbergs suggestions here