With apoc 4.4, when I try to declare a function that modifies a MAP value, the returned MAP is wrapped inside another map with the key of the outer map being the name of the last expression. For example:
CALL apoc.custom.declareFunction('answer(map ...