Unfortunately cursor history is discarded when the DecodeResult[T]
object is built for success case.
The only solution I can think of (it is just a stub to explain you the concept) is to:
- implement a custom
HistoryDecodeResult
:
class HistoryDecodeResult[A](
val h: Option[CursorHistory],
result: \/[(String, CursorHistory),A]
) extends DecodeResult[A](result)
object HistoryDecodeResult{
def apply[A](h: Option[CursorHistory], d: DecodeResult[A]) = new HistoryDecodeResult(h, d.result)
}
- implicitly extend
ACursor
adding an helper asH
method
implicit class AHCursor(a: ACursor){
def asH[A](implicit d: DecodeJson[A]): HistoryDecodeResult[A] = {
HistoryDecodeResult(a.hcursor.map(_.history), a.as[A](d))
}
}
- override
DecodeResult[T]
composition methods within HistoryDecodeResult
in order to accumulate the history:
override def map[B](f: A => B): HistoryDecodeResult[B] =
HistoryDecodeResult(h, super.map(f))
//Accumulate history `h` using `CursorHistory.++` if flat-mapping with another HistoryDecodeResult
override def flatMap[B](f: A => DecodeResult[B]): HistoryDecodeResult[B] = ???
... //Go on with other methods
- obtain the
HistoryDecodeResult
from your decoding routine (you have to avoid Parse.decode
) and ask for history.