From 86077e92ae9a3695e1661679f7def0516723b4b7 Mon Sep 17 00:00:00 2001 From: feedmeapples Date: Wed, 22 Feb 2023 19:05:47 -0500 Subject: [PATCH] Make iterator printer generic --- pkg/iterator/iterator.go | 16 +++++++--------- pkg/output/printer.go | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/iterator/iterator.go b/pkg/iterator/iterator.go index 059fafb..cdd2978 100644 --- a/pkg/iterator/iterator.go +++ b/pkg/iterator/iterator.go @@ -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) +} diff --git a/pkg/output/printer.go b/pkg/output/printer.go index e0637ac..3842bb3 100644 --- a/pkg/output/printer.go +++ b/pkg/output/printer.go @@ -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 {