diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-08-18 18:01:44 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-08-18 18:01:44 -0400 |
| commit | 4f0f92e1a7fc67ec2521e2acb5ba7c60f0d6dcc6 (patch) | |
| tree | 843618e9801b146fa708800cadc22e8c4dd3719c | |
| parent | 9432f7d1c143c426ab011770431827b9c055b7e9 (diff) | |
| download | share-4f0f92e1a7fc67ec2521e2acb5ba7c60f0d6dcc6.zip | |
simplify ConstSlice.Elems()
| -rw-r--r-- | slice.go | 11 |
1 files changed, 2 insertions, 9 deletions
@@ -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 } |