Skip to content

Official Iterator support after Go 1.23 #33

@leonardodalinky

Description

@leonardodalinky

It seems that Golang has made a "range-over-function" feature after Go 1.23, which is included in the standard library iter (doc). I wonder if there are plans to implement these newly added interface in the later versions?

For example, we can add a .iter() method to each container types. I believe this would not break the existing logic:

package main

import (
  "fmt"
  "github.com/liyue201/gostl/ds/list/simplelist"
)

func main() {
  l := simplelist.New[int]()
  l.PushBack(1)
  l.PushFront(2)
  l.PushFront(3)
  l.PushBack(4)
  for ele := range l.iter() {
    // Do something
  }
  fmt.Printf("\n===============\n")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions