Go Iterators Rangefunc

Guides writing and consuming Go push iterators (range-over-func, Go 1.23) — an iter.Seq[V] is func(yield func(V) bool), the iterator calls yield per element and MUST stop calling it the moment yield returns false (the central bug is ignoring that bool — the runtime panics on a yield call after it returned false), range translates break/continue/return through yield, iter.Pull converts push→pull and you MUST call its stop, and the restraint rule is don't wrap a slice you already have in an iterator — return the slice. Covers iter.Seq/Seq2, slices.All/Values/Backward/Collect/Sorted, maps.Keys/Values/Collect, and Seq2 with a trailing error. Auto-invokes when writing or editing iterator functions, iter.Seq/Seq2, range-over-func, yield callbacks, iter.Pull, or on "how do I make this rangeable" / "should this return an iterator or a slice". Honor yield's bool; don't iteratorize a slice for fashion.

ctoth Updated 1 repo stars

File contents

ctoth/golang-skills-plugin commit 0b83f0db7f

Frequently asked questions

npx get-skill add ctoth/go-iterators-rangefunc