Currently, Combine requires the caller to structure their code so as to unify the types involved. This is just one option; another is to use a signature like the below:
Merge[S,T any](ctx context.Context, in1 <-chan T, in2 <-chan S) <-chan Pair[S,T]
...along with a generic Pair type....
type Pair[S, T any] struct {
First S; Second T
}
But I don't think this package should introduce a generic Pair type. This would also require blocking one half of a combined pipeline in order to allow the other to catch up, which can, of course, get a teeny bit fraught.
Yet another, more viable option is:
// Merge combines values from in1 and in2. Each pair of values received is passed to combiner. After in1 is closed,
// all values received on in2 are passed to combiner, paired with a nil value of *S. Likewise, after in2 is closed, all
// values received on in1 are passed to combiner, paired with a nil value of *T.
Merge[S,T,U any](ctx context.Context, in1 <-chan T, in2 <-chan S, combiner func(*S, *T) U) <-chan U
It's unclear whether either of these API options are better than having the caller align on a unified type as part of pipeline stages upstream. They both introduce some additional complexity.
Currently, Combine requires the caller to structure their code so as to unify the types involved. This is just one option; another is to use a signature like the below:
...along with a generic Pair type....
But I don't think this package should introduce a generic
Pairtype. This would also require blocking one half of a combined pipeline in order to allow the other to catch up, which can, of course, get a teeny bit fraught.Yet another, more viable option is:
It's unclear whether either of these API options are better than having the caller align on a unified type as part of pipeline stages upstream. They both introduce some additional complexity.