Skip to content

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