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

Add Seq and SeqLEK (Go 1.23 iterators) #244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add Seq and SeqLEK (Go 1.23 iterators) #244

wants to merge 2 commits into from

Conversation

guregu
Copy link
Owner

@guregu guregu commented Aug 14, 2024

Here's an initial implementation of Go 1.23-style iterators for Iter and PagingIter. Not sure yet if this would be the best API, or if it's useful 🤔

It lets you write code like this

iter := table.Get("UserID", 1971).Iter()
for item := range dynamo.Seq[Widget](ctx, iter) {
	// do something with item
}

instead of this:

iter := table.Get("UserID", 1971).Iter()
var item Widget
for iter.Next(ctx, &item) {
	// do something with item
}

dynamo.SeqLEK lets you do for lastEvaluatedKey, item := range dynamo.SeqLEK(...).

My thoughts are that it's kind of useful, but would probably be more useful as a method of a potential Schema[T any] type that stores information about the primary keys, etc (which is something I'd like to add eventually).

Comments or ideas are welcome.

@guregu
Copy link
Owner Author

guregu commented Aug 14, 2024

An iterator for BatchGet that returns the table and item would be nice too (see also: #242). Although, you'd have to manually deserialize items if you have multiple types and need to switch on the table name, so it won't change things too much.

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