Since Functions are not JSON serializable, i guess you cannot send a function to the server.
Anyway, that would be a bad idea on a security point of view, if the server has some code to execute, it should come from the server, imho.
Don’t try to pass a function, because you can’t. Put the logic from the function in the publication and just pass the index as a parameter. You can have multiple publications if you need and the client can subscribe to wher whichever it needs.