Sometimes you want to write bash macros instead of bash functions.
You want to write some bash which can declare local variables in the caller context.
Maybe it parses some data and creates a bunch of hashes with a known prefix (that's as much namespace management as bash gives you) and populates a named list with the names of those hashes.
And then you need to use that twice so you want to factor it into a function. Only you can't these aren't meant to be global variables.
So you have a few solutions, all using source in one way or another
You could put it into a separate file and source it whenever you need it.
You could define it in a string or here document and source it when needed (but you loose bash syntax support in the editor).
You can call the function using command substitution and have it execute declare -p on the variables you want to export.
e.g. source <( my-function args )
Or to enjoy all the side effects directly, you can export the function body using declare -f and strip the first line (which is the function declaration) my masking it with a comment, and then execute the rest directly, using source.
And to invoke it:
Maybe source <( function-body my-function ) "$@" is a bit verbose when calling a function inline every time.
Note the double-eval mechanism so that <<< can be used to read the function name on stdin while the remaining arguments are applied to the body as $@ for the lifetime of the body (thanks, bash)