summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-08-18 18:01:44 -0400
committerSam Anthony <sam@samanthony.xyz>2024-08-18 18:01:44 -0400
commit4f0f92e1a7fc67ec2521e2acb5ba7c60f0d6dcc6 (patch)
tree843618e9801b146fa708800cadc22e8c4dd3719c
parent9432f7d1c143c426ab011770431827b9c055b7e9 (diff)
downloadshare-4f0f92e1a7fc67ec2521e2acb5ba7c60f0d6dcc6.zip
simplify ConstSlice.Elems()
-rw-r--r--slice.go11
1 files changed, 2 insertions, 9 deletions
diff --git a/slice.go b/slice.go
index 0be8f3e..68660a0 100644
--- a/slice.go
+++ b/slice.go
@@ -16,15 +16,8 @@ func NewConstSlice[T any](slc []T) ConstSlice[T] {
// Elems returns a channel that yields each successive element of the slice.
// Once drained, the channel is closed automatically, and therefore should NOT be closed again by the caller.
func (cs ConstSlice[T]) Elems() <-chan T {
- elems := make(chan T) // will be closed by request handler
- cs.requests <- elems
- c := make(chan T)
- go func() {
- defer close(c)
- for elem := range elems {
- c <- elem
- }
- }()
+ c := make(chan T) // will be closed by request handler
+ cs.requests <- c
return c
}