package node type Input[X any] struct { ID string Ch <-chan X } type Output[X any] struct { ID string Ch chan<- X } type Duplex[X any] struct { ID string Ch chan X } func (n Duplex[X]) AsInput() Input[X] { return Input[X]{n.ID, n.Ch} } func (n Duplex[X]) AsOutput() Output[X] { return Output[X]{n.ID, n.Ch} } func (n *Duplex[X]) Init(id string, bufsize int) { n.ID = id n.Ch = make(chan X, bufsize) } func New[X any](id string, bufsize int) *Duplex[X] { var n Duplex[X] (&n).Init(id, bufsize) return &n } func (n Duplex[X]) Connect(o withOutput[X], i withInput[X]) { o.AddOutput(n.ID, n.AsOutput()) i.AddInput(n.ID, n.AsInput()) } type withInput[X any] interface { AddInput(string, Input[X]) } type withOutput[X any] interface { AddOutput(string, Output[X]) }