@@ -18,22 +18,14 @@ import (
18
18
"go.structs.dev/gen"
19
19
)
20
20
21
- type readonly [T any ] interface {
22
- <- chan T | chan T
23
- }
24
-
25
- type writeonly [T any ] interface {
26
- chan <- T | chan T
27
- }
28
-
29
21
// Pipe accepts an incoming data channel and pipes it to the supplied
30
22
// outgoing data channel.
31
23
//
32
24
// NOTE: Execute the Pipe function in a goroutine if parallel execution is
33
25
// desired. Canceling the context or closing the incoming channel is important
34
26
// to ensure that the goroutine is properly terminated.
35
- func Pipe [In readonly [ T ], Out writeonly [ T ], T any ](
36
- ctx context.Context , in In , out Out ,
27
+ func Pipe [T any ](
28
+ ctx context.Context , in <- chan T , out chan <- T ,
37
29
) {
38
30
ctx = _ctx (ctx )
39
31
@@ -62,9 +54,9 @@ type InterceptFunc[T, U any] func(context.Context, T) (U, bool)
62
54
// indicating whether the data should be forwarded to the output channel.
63
55
// The function is executed for each data item in the incoming channel as long
64
56
// as the context is not canceled or the incoming channel remains open.
65
- func Intercept [In readonly [ T ], T , U any ](
57
+ func Intercept [T , U any ](
66
58
ctx context.Context ,
67
- in In ,
59
+ in <- chan T ,
68
60
fn InterceptFunc [T , U ],
69
61
) <- chan U {
70
62
ctx = _ctx (ctx )
@@ -112,7 +104,7 @@ func Intercept[In readonly[T], T, U any](
112
104
// NOTE: The transfer takes place in a goroutine for each channel
113
105
// so ensuring that the context is canceled or the incoming channels
114
106
// are closed is important to ensure that the goroutine is terminated.
115
- func FanIn [In readonly [ T ], T any ](ctx context.Context , in ... In ) <- chan T {
107
+ func FanIn [T any ](ctx context.Context , in ... <- chan T ) <- chan T {
116
108
ctx = _ctx (ctx )
117
109
out := make (chan T )
118
110
@@ -147,8 +139,8 @@ func FanIn[In readonly[T], T any](ctx context.Context, in ...In) <-chan T {
147
139
// NOTE: Execute the FanOut function in a goroutine if parallel execution is
148
140
// desired. Canceling the context or closing the incoming channel is important
149
141
// to ensure that the goroutine is properly terminated.
150
- func FanOut [In readonly [ T ], Out writeonly [ T ], T any ](
151
- ctx context.Context , in In , out ... Out ,
142
+ func FanOut [T any ](
143
+ ctx context.Context , in <- chan T , out ... chan <- T ,
152
144
) {
153
145
ctx = _ctx (ctx )
154
146
@@ -207,8 +199,8 @@ func FanOut[In readonly[T], Out writeonly[T], T any](
207
199
// NOTE: Execute the Distribute function in a goroutine if parallel execution is
208
200
// desired. Canceling the context or closing the incoming channel is important
209
201
// to ensure that the goroutine is properly terminated.
210
- func Distribute [In readonly [ T ], Out writeonly [ T ], T any ](
211
- ctx context.Context , in In , out ... Out ,
202
+ func Distribute [T any ](
203
+ ctx context.Context , in <- chan T , out ... chan <- T ,
212
204
) {
213
205
ctx = _ctx (ctx )
214
206
@@ -244,7 +236,7 @@ func Distribute[In readonly[T], Out writeonly[T], T any](
244
236
245
237
// Drain accepts a channel and drains the channel until the channel is closed
246
238
// or the context is canceled.
247
- func Drain [U readonly [ T ], T any ](ctx context.Context , in U ) {
239
+ func Drain [T any ](ctx context.Context , in <- chan T ) {
248
240
ctx = _ctx (ctx )
249
241
250
242
go func () {
@@ -263,7 +255,7 @@ func Drain[U readonly[T], T any](ctx context.Context, in U) {
263
255
264
256
// Any accepts an incoming data channel and converts the channel to a readonly
265
257
// channel of the `any` type.
266
- func Any [U readonly [ T ], T any ](ctx context.Context , in U ) <- chan any {
258
+ func Any [T any ](ctx context.Context , in <- chan T ) <- chan any {
267
259
return Intercept (ctx , in , func (_ context.Context , in T ) (any , bool ) {
268
260
return in , true
269
261
})
0 commit comments