Closed geny200 closed 5 months ago
Could you please provide a use case for an encoder for Nothing?
Hi, I have a strange case, but still, for example, take Either, which can only have Right values (but only in our part of the service, in other places it can also be Left). You will need Nothing encoder for it.
yes, it is a fair remark that the law x == decode(encode(x)) is not fulfilled, but there is a slight difference, when encoding we know more information, and we can guarantee that there will be a certain type. When decoding, you need to decode the general type.
Hi, I have a strange case, but still, for example, take Either, which can only have Right values (but only in our part of the service, in other places it can also be Left). You will need Nothing encoder for it.
Wouldn't creating an encoder for Right / Left solve this problem? It seems like a more straightforward and explicit approach
Wouldn't creating an encoder for Right / Left solve this problem?
Not really, especially when you derive implicits for own types, and hide the fact that Right/Left is used inside. I was inspired by the Loggable
instance from tofu (Loggable for Nothing
).
creating an encoder for Right / Left
By suggesting this, you have raised another problem, that we can't write a common encoder and decoder for Either, so based on this, we cannot write common codecs for Left and Right.
Hi!
I apologize for the delay in my response.
To be honest, I still don't fully understand your use case for Nothing
. These instances seem a bit strange to me, but I couldn't find any issues that it might cause. Therefore, I will merge the PR
Hi! Could you please provide a use case for an encoder for
Nothing
? Such encoder would violate the laws for Encoder/Decoder, becausex == decode(encode(x))
wherex
is of typeNothing
would not compile, because a decoder forNothing
does not exist. On the other hand, one cannot run such code, because it is impossible to create an instance ofNothing
. Instances forNothing
are strange, but I don't mind adding them, if there is a need