This reminded me of something that happened last week. I had written some code I found absolutely beautiful, then had to delete an hour later since the customer's requirements had changed. Personally, I find these situations disheartening but it's never frustrated me.
Every line of code that you write and can be proud of stays with you and adds up to your experience. You will produce more of it as you gain more experience.