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

Make iterator printer generic #39

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions pkg/iterator/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@

package iterator

type (
// Iterator represents the interface for iterator
Iterator interface {
// HasNext return whether this iterator has next value
HasNext() bool
// Next returns the next item and error
Next() (interface{}, error)
}
)
// Iterator represents the interface for iterator
type Iterator[C any] interface {
// HasNext return whether this iterator has next value
HasNext() bool
// Next returns the next item and error
Next() (C, error)
}
2 changes: 1 addition & 1 deletion pkg/output/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func PrintItems(c *cli.Context, items []interface{}, opts *PrintOptions) error {
}

// PrintIterator prints items from an iterator based on user flags or print options.
func PrintIterator(c *cli.Context, iter iterator.Iterator, opts *PrintOptions) error {
func PrintIterator(c *cli.Context, iter iterator.Iterator[interface{}], opts *PrintOptions) error {
limit := c.Int(FlagLimit)

if opts == nil {
Expand Down