by binary132 · 3y ago · 0 comments
```
type Iter[T] interface { More() bool It() T }
type mapOver[T] struct { Iter[T]; func (T) T f }
func (m mapOver[T]) It() T { return m.f(m.Iter.It()) }
func Map[T] (it Iter[T], f func(T) T) Iter[T] { return mapOver{it, f} }
type Range { to, at int }
func (r Range) More() bool { return r.at < r.to }
func (r Range) It() (is int) { is = r.at; r.at += 1 }
func DoEach[T] (it Iter[T], f func(T) T) { for it.More() { f(it.It()) } }
// etc
iter.DoEach(iter.Range(10), fx.Stdout(fns.MultBy(2)))
// or whatever
```
Translating to English:
If you can do it just fine with the syntax you have, why do you need to add it to the core language?