It may happen more often in agile teams, but then there's less to "throw away", as they make small steps, and detect they're wrong earlier. If you first spend 6 months designing, then 6 months implementing, and it turns there's a flaw in the design and it's back to the drawing boards. It may have taken you a year to get to a case that needs scrapping, but there's a huge cost for that one time.
But still, it's not the same as scrapping metal. If you have a production line producing expensive, complicated cuts, doing the last cut wrong is expensive. The metal has to be scrapped, and the time spend so far is completely wasted. But coding isn't the same - there's no "scrap" in the sense of a complete wasted effort. As Thomas Edison said "I have not failed. I have found 10000 ways that do not work". Taking a decision (whether it's in the design phase, or in the coding phase) that turns out to not work, does have value. You now know what doesn't work.
One may argue that a baby that keeps falling over is wasting effort: it should spend a few months studying how people walk, then walk on its first try. But babies don't. They try. They fail. They learn from failure. In the end, they walk.