Indeed. Electricity and magnetic fields are so closely related we have a single term, electromagnetism, the motor and generator are thus almost the same thing and it's relatively easy to build a single device which can serve both purposes.
Actually regenerative braking is common on electric trains. Stock bought since at least the 1990s for London Underground has regenerative braking of various forms, with the more modern being fitted to S-stock (the sub-surface lines which were all gradually replaced with a single type of train, if you went on a "Tube" train and it was actually walk-through the length of the train and seemed vaguely modern inside, that was S-stock and you weren't in the deep tube where heat is a bigger problem)
In the 1970s when the oldest stock still in use was purchased, regenerative braking was not a thing.