To serve as a lesson. There would really be some people who wouldn't stay in your life. You just have to accept that fact and cherish whatever moment you had with her/him (either good or bad) then move on with your life :) Bring with you all the lessons you learned then continue to grow as a better person :)