3

For a composite interface e.g.

type io.ReadWriter interface {
    io.Reader
    io.Writer
}

Is it possible to wrap the implementation instance on the fly from separate partial implementations without defining intermediate proxy structures types

func() io.ReadWriter {
    var reader io.Reader
    var writer io.Writer

    return ...
}

e.g. something like io.ReadWriter{reader, writer}. Or is the most shorthand inline approach would be only like this?

return struct{
    io.Reader
    io.Writer
}{
    reader, 
    writer
}
hypp erster
  • 139
  • 7
  • 2
    your last snippet would work ; there is no inline declaration that would look like your first attempt. – LeGEC May 22 '22 at 17:16

0 Answers0