Going Backward

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

A thought experiment walking through the iterative design decisions behind Go's slices.Backward function. Starting from a naive slice-copying approach, the post evolves the implementation step by step: from a closure-based pull iterator, to a callback-based push iterator with a yield function, to adding index-value pairs (Seq2), and finally to supporting user-defined slice types using the ~T generic constraint. Each step explains the tradeoff that motivates the next, ultimately arriving at the same signature found in Go's standard library.

9m read timeFrom antonz.org
Post cover image
Table of contents
1. A slice in reverse2. Gimme, gimme, gimme3. A callback-based iterator4. Iterator 2: Return of the Iterator5. Not quite a slice6. Iterator 3: Judgment Day
51.5K Impressions3 Comments