logoalt Hacker News

klibertptoday at 3:10 PM0 repliesview on HN

TL;DR: if you want a general looping construct that works no matter the container type, you need an iterator protocol that types can opt into. This is a standard technique adopted by most programming languages that are not explicitly low-level, and has existed for the past 60[1] years. The OP (re)discovered it and thought it was worth blogging about.

Well, it is kind of interesting to see how the very basic programming building block (iteration) gets generalized without incurring syntactic costs. Whether it's worth a place on the HN front page is debatable, though.

[1] Too lazy to track the actual first implementation, but I'd be astonished if the concept wasn't well-known by the 70's.