These operations would help but they're not unique to errors, even though they most often arise in that context.
Since this proposal relies on some form of generics to implement As
, why not make the interface and both operations generic so we can Is
or As
a wrapped io.Reader
just as easily?
I think these operations actually are fairly unique to errors. Errors are different from most other interface values in that you almost always need to covert them to some other type in order to use them for any purpose other than printing. An
io.Reader
is useful as it is.Optional ancillary methods such as
io.ReaderAt
are an exception. I'm guessing you might be suggesting this as a way to address the case where you want to wrap something with optional methods like these? I don't thinkIs
andAs
offer much here. If the wrapper implementsUnwrap
, thenAs(wrappedReader, io.ReaderAt)
will return the underlying reader without whatever additional functionality is provided by the wrapper type.