I don’t know Kotlin myself so I’m not able to judge what you posted; but, if you don’t know it either, ChatGPT may well have generated an answer experts would qualify as bad or incomplete (the forum rules advise against posting generated content and that is one reason).
Here, map
should be a “functor”, that is it should in particular preserve the generic container type, so returning a list systematically looks completely incorrect. I don’t know if this is the only possible solution in Kotlin or if ChatGPT gave a wrong answer.
Finally, my goto-example to illustrate the power of functors is OCamlgraph.