Skip to content

Commit 84bb222

Browse files
committed
simplify
1 parent 53f6a7c commit 84bb222

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

internal/fwserver/server_listresource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestServerListResource(t *testing.T) {
8383
request: &fwserver.ListRequest{
8484
ListResource: &testprovider.ListResource{
8585
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { // TODO
86-
resp.Results = slices.Values([]list.ListResult{})
86+
resp.Results = list.NoListResults
8787
},
8888
},
8989
},
@@ -110,7 +110,7 @@ func TestServerListResource(t *testing.T) {
110110
request: &fwserver.ListRequest{
111111
ListResource: &testprovider.ListResource{
112112
ListMethod: func(ctx context.Context, req list.ListRequest, resp *list.ListResultsStream) { // TODO
113-
resp.Results = slices.Values([]list.ListResult{
113+
resp.Results = list.FromValues([]list.ListResult{
114114
{
115115
Identity: &tfsdk.ResourceIdentity{
116116
Schema: testIdentitySchema,

list/list_resource.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package list
55

66
import (
77
"context"
8+
"slices"
89

910
"github.com/hashicorp/terraform-plugin-framework/diag"
1011
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -104,9 +105,7 @@ type ListRequest struct {
104105
// that pushes zero or more results of type ListResult.
105106
//
106107
// For convenience, a provider implementation may choose to convert a slice of
107-
// results into an iterator using [slices.Values].
108-
//
109-
// [slices.Values]: https://pkg.go.dev/slices#Values
108+
// results into an iterator using [list.FromValues].
110109
type ListResultsStream struct {
111110
// Results is a function that emits ListResult values via its push
112111
// function argument.
@@ -120,6 +119,12 @@ type ListResults func(push func(ListResult) bool)
120119

121120
var NoListResults = func(func(ListResult) bool) {}
122121

122+
// FromValues converts a slice of ListResult values into a ListResults
123+
// iterator for streaming.
124+
func FromValues(values []ListResult) ListResults {
125+
return ListResults(slices.Values(values))
126+
}
127+
123128
// ListResult represents a listed managed resource instance.
124129
type ListResult struct {
125130
// Identity is the identity of the managed resource instance.

0 commit comments

Comments
 (0)