You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I've needed to provide my own Show[Expectation] but wanted to keep Show[Error] as is. It turns out it's not possible, as the latter doesn't take Show[Expectation] as a parameter. Example code (runnable via scala-cli):
//>usingdep"org.typelevel::cats-parse:1.0.0"//>usingscala2.13importcats.parse.Parserimportcats.parse.Parser.{Error, Expectation}
importcats.Showimportcats.syntax.show._valparseError:Error=Parser.string("something").parseAll("smth").swap.toOption.get
implicitvalshowExpectation:Show[Expectation] =newShow[Expectation] {
overridedefshow(exp: Expectation) ="myImpl"
}
println(show"$parseError")
/* prints this (showExpectation is apparently ignored): smth ^ expectation: * must match string: "something"*/
It appears to be necessary to copy Show[Error] verbatim if one wants to customise how the expectations are rendered.
I think it wouldn't be necessary if this definition:
To be honest I know my use case is very, very niche, but I thought I'd share this suggestion in case it appears useful. On the other hand, if the suggestion is wrong for some reason, I'll be happy to learn
The text was updated successfully, but these errors were encountered:
Recently I've needed to provide my own
Show[Expectation]
but wanted to keepShow[Error]
as is. It turns out it's not possible, as the latter doesn't takeShow[Expectation]
as a parameter. Example code (runnable via scala-cli):It appears to be necessary to copy
Show[Error]
verbatim if one wants to customise how the expectations are rendered.I think it wouldn't be necessary if this definition:
were changed to
To be honest I know my use case is very, very niche, but I thought I'd share this suggestion in case it appears useful. On the other hand, if the suggestion is wrong for some reason, I'll be happy to learn
The text was updated successfully, but these errors were encountered: