@@ -18,22 +18,14 @@ import (
1818 "go.structs.dev/gen"
1919)
2020
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-
2921// Pipe accepts an incoming data channel and pipes it to the supplied
3022// outgoing data channel.
3123//
3224// NOTE: Execute the Pipe function in a goroutine if parallel execution is
3325// desired. Canceling the context or closing the incoming channel is important
3426// 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 ,
3729) {
3830 ctx = _ctx (ctx )
3931
@@ -62,9 +54,9 @@ type InterceptFunc[T, U any] func(context.Context, T) (U, bool)
6254// indicating whether the data should be forwarded to the output channel.
6355// The function is executed for each data item in the incoming channel as long
6456// 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 ](
6658 ctx context.Context ,
67- in In ,
59+ in <- chan T ,
6860 fn InterceptFunc [T , U ],
6961) <- chan U {
7062 ctx = _ctx (ctx )
@@ -112,7 +104,7 @@ func Intercept[In readonly[T], T, U any](
112104// NOTE: The transfer takes place in a goroutine for each channel
113105// so ensuring that the context is canceled or the incoming channels
114106// 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 {
116108 ctx = _ctx (ctx )
117109 out := make (chan T )
118110
@@ -147,8 +139,8 @@ func FanIn[In readonly[T], T any](ctx context.Context, in ...In) <-chan T {
147139// NOTE: Execute the FanOut function in a goroutine if parallel execution is
148140// desired. Canceling the context or closing the incoming channel is important
149141// 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 ,
152144) {
153145 ctx = _ctx (ctx )
154146
@@ -207,8 +199,8 @@ func FanOut[In readonly[T], Out writeonly[T], T any](
207199// NOTE: Execute the Distribute function in a goroutine if parallel execution is
208200// desired. Canceling the context or closing the incoming channel is important
209201// 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 ,
212204) {
213205 ctx = _ctx (ctx )
214206
@@ -244,7 +236,7 @@ func Distribute[In readonly[T], Out writeonly[T], T any](
244236
245237// Drain accepts a channel and drains the channel until the channel is closed
246238// 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 ) {
248240 ctx = _ctx (ctx )
249241
250242 go func () {
@@ -263,7 +255,7 @@ func Drain[U readonly[T], T any](ctx context.Context, in U) {
263255
264256// Any accepts an incoming data channel and converts the channel to a readonly
265257// 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 {
267259 return Intercept (ctx , in , func (_ context.Context , in T ) (any , bool ) {
268260 return in , true
269261 })
0 commit comments