Skip to content

Implement Go 1.23 iterators#41

Merged
elliotchance merged 3 commits intoelliotchance:masterfrom
thiagokokada:go123-iterators
Aug 17, 2024
Merged

Implement Go 1.23 iterators#41
elliotchance merged 3 commits intoelliotchance:masterfrom
thiagokokada:go123-iterators

Conversation

@thiagokokada
Copy link
Contributor

@thiagokokada thiagokokada commented Aug 16, 2024

Close issue: #40.

This PR implements Iterator() and ReverseIterator() methods, that allow usage with for ... range in Go 1.23:

for key, value := range m.Iterator() {
    fmt.Println(key, value)
}

for key, value := range m.ReverseIterator() {
    fmt.Println(key, value)
}

This change is Reviewable

}
}

func (m *OrderedMap[K, V]) ReverseIterator() iter.Seq2[K, V] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I like this name, so I am open for a better name here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me

Comment on lines +20 to +21
- run: go test -v ./...
- run: cd v2 && go test -v ./...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go will only run the tests for the current module directory and not for the modules inside subdirectories, so this means that without explicitly running for v2, the tests would run only for github.com/elliotchance/orderedmap, and not for github.com/elliotchance/orderedmap/v2.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

}
}

func (m *OrderedMap[K, V]) ReverseIterator() iter.Seq2[K, V] {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me

Comment on lines +20 to +21
- run: go test -v ./...
- run: cd v2 && go test -v ./...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@elliotchance elliotchance merged commit 9767ae7 into elliotchance:master Aug 17, 2024
@thiagokokada thiagokokada deleted the go123-iterators branch August 17, 2024 22:41
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.

2 participants