These are chat archives for fthomas/refined

25th
Aug 2015
Frank S. Thomas
@fthomas
Aug 25 2015 08:59
@koshelev Encoding the result with the values of the predicates might make the pattern matching nicer case Xor.Left(Failed(And(Passed(True()), Failed(False()))) => ... where Passed and Failed state which of the nested predicates failed or passed
Vladimir Koshelev
@koshelev
Aug 25 2015 09:06
@fthomas Seems so.
sealed trait Result
final case class Failed[P](p : P) extends Result
final case class Passed[P](p: P) extends Result
is that what you have in mind?
Frank S. Thomas
@fthomas
Aug 25 2015 09:13
Yes! Result should also have the type parameter: Result[P]
Frank S. Thomas
@fthomas
Aug 25 2015 09:21
Do you think that makes sense?
Vladimir Koshelev
@koshelev
Aug 25 2015 09:25
@fthomas I think it does, but it still does not feel right ;)
What signature of And do you have in mind?
Frank S. Thomas
@fthomas
Aug 25 2015 09:28
@koshelev case class And[A, B](a: A, b: B)
Maybe we should start backwards from what feels right and then try to implement that.
Vladimir Koshelev
@koshelev
Aug 25 2015 09:29
@fthomas ok, and the signature of the predicate as I proposed in the gist?
Frank S. Thomas
@fthomas
Aug 25 2015 09:31
@koshelev similar to the signature you have right now but with type Out = Result[And[AOut, BOut]]
not sure if IsSuccess is still needed then, probably not since that is encoded in Result
Vladimir Koshelev
@koshelev
Aug 25 2015 09:36
@fthomas I think it actually good solution. We can pattern match on the result, and we can convert it in tree represented by HList if we would like apply smth. generic to the result.
Frank S. Thomas
@fthomas
Aug 25 2015 09:42
@koshelev and with the precise result type we should be able to construct error messages using Show instances similar to error messages that Predicate.validated provides now
Vladimir Koshelev
@koshelev
Aug 25 2015 09:44
@fthomas Yes, we will be able both provide nice string representation and convert it to come another representation (my use case is to convert it to list of error codes)
Frank S. Thomas
@fthomas
Aug 25 2015 09:45
Result probably also need to carry the T around for good error messages, see https://github.com/fthomas/refined/blob/master/shared/src/main/scala/eu/timepit/refined/Predicate.scala#L86-L90
Vladimir Koshelev
@koshelev
Aug 25 2015 09:48
Sure
Frank S. Thomas
@fthomas
Aug 25 2015 17:44
@koshelev I've pushed a very minimal and dirty implementation of your idea with Result to the https://github.com/fthomas/refined/tree/wip/errors-as-data branch. It should be just enough to play around with this idea
scala> refineT[And[True, True]](1)
res0: Either[eu.timepit.refined.Result[eu.timepit.refined.boolean.And[eu.timepit.refined.Result[eu.timepit.refined.boolean.True],eu.timepit.refined.Result[eu.timepit.refined.boolean.True]]],shapeless.tag.@@[Int,eu.timepit.refined.boolean.And[eu.timepit.refined.boolean.True,eu.timepit.refined.boolean.True]]] = Right(1)

scala> refineT[And[True, False]](1)
res1: Either[eu.timepit.refined.Result[eu.timepit.refined.boolean.And[eu.timepit.refined.Result[eu.timepit.refined.boolean.True],eu.timepit.refined.Result[eu.timepit.refined.boolean.False]]],shapeless.tag.@@[Int,eu.timepit.refined.boolean.And[eu.timepit.refined.boolean.True,eu.timepit.refined.boolean.False]]] = Left(Failed(And(Passed(True()),Failed(False()))))
Frank S. Thomas
@fthomas
Aug 25 2015 17:52
any PR against this branch is accepted without further ado ;-)