Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sets: implement .Items() for use with range keyword #82

Closed
wants to merge 1 commit into from

Conversation

shoenig
Copy link
Member

@shoenig shoenig commented Feb 21, 2024

This PR adds a .Items() method on each of Set, HashSet, and TreeSet
enabling each type to be used with the range keyword for iteration.

for element := range s.Items() {
  // ...
}

Note this is currently an experimental feature of Go 1.22
https://go.dev/wiki/RangefuncExperiment

This PR adds a .Items() method on each of Set, HashSet, and TreeSet
enabling each type to be used with the `range` keyword for iteration.

    for element := range s.Items() {
      // ...
    }

Note this is currently an experimental feature of Go 1.22
https://go.dev/wiki/RangefuncExperiment
shoenig added a commit that referenced this pull request Aug 15, 2024
Starting with go1.23, Go supports using `range` with custom user types
that satisfy interfaces of the `iter` package. We can make use of this
functionality for iterating over elements of each type of set.

```go
s := set.From([]int{2, 1, 1, 3})
for item := range s.Items() {
  fmt.Println(item)
}
```

This functionality replaces the need for the `ForEach` defined on each
set type, and so that method is removed. This means we need a v3 breaking
change for the release.

Closes #82
@shoenig shoenig closed this in #91 Aug 16, 2024
shoenig added a commit that referenced this pull request Aug 16, 2024
Starting with go1.23, Go supports using `range` with custom user types
that satisfy interfaces of the `iter` package. We can make use of this
functionality for iterating over elements of each type of set.

```go
s := set.From([]int{2, 1, 1, 3})
for item := range s.Items() {
  fmt.Println(item)
}
```

This functionality replaces the need for the `ForEach` defined on each
set type, and so that method is removed. This means we need a v3 breaking
change for the release.

Closes #82
@shoenig shoenig deleted the rangefunc branch August 16, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant