Can bad relationships be beneficial for the future?

Yes. Yes.
Depends on learning. Bad relationship gives opportunity for you to learn something about yourself, about your vulnerabilities, and wisdom that you can put to use. This is easier said than done - and that's why history tend to repeat. Look within yourself to understand the role you played in the bad relationship. What can you change to build a better future relationship? It will take more than finding a better partner.