1 package io.taig.circe
2 
3 import cats.data.{Validated, ValidatedNel}
4 import io.circe.{Decoder, DecodingFailure, HCursor, ValidatingDecoder}
5 
6 package object validation {
7   implicit final class RichValidationDecoder[A](val decoder: Decoder[A])
8       extends AnyVal {
9     def verify[B](lift: A => ValidatedNel[String, B]): ValidatingDecoder[B] =
10       ValidatingDecoder.instance { cursor =>
11         Validated
12           .fromEither(decoder(cursor))
13           .toValidatedNel
14           .andThen(liftDecodingFailures(lift, cursor))
15       }
16 
17     private def liftDecodingFailures[B](
18         lift: A => ValidatedNel[String, B],
19         cursor: HCursor
20     ): A => ValidatedNel[DecodingFailure, B] =
21       lift.andThen(_.leftMap(_.map(DecodingFailure(_, cursor.history))))
22   }
23 }
Line Stmt Id Pos Tree Symbol Code
10 25 346 - 530 Apply io.circe.ValidatingDecoder.instance io.circe.ValidatingDecoder.instance[B](((cursor: io.circe.HCursor) => cats.data.Validated.fromEither[io.circe.DecodingFailure, A](RichValidationDecoder.this.decoder.apply(cursor)).toValidatedNel[io.circe.DecodingFailure, A].andThen[cats.data.NonEmptyList[io.circe.DecodingFailure], B](RichValidationDecoder.this.liftDecodingFailures[B](lift, cursor))))
10 10 346 - 530 Apply io.circe.ValidatingDecoder.instance io.circe.ValidatingDecoder.instance[B](((cursor: io.circe.HCursor) => cats.data.Validated.fromEither[io.circe.DecodingFailure, A](RichValidationDecoder.this.decoder.apply(cursor)).toValidatedNel[io.circe.DecodingFailure, A].andThen[cats.data.NonEmptyList[io.circe.DecodingFailure], B](RichValidationDecoder.this.liftDecodingFailures[B](lift, cursor))))
12 23 425 - 440 Apply io.circe.Decoder.apply RichValidationDecoder.this.decoder.apply(cursor)
12 8 425 - 440 Apply io.circe.Decoder.apply RichValidationDecoder.this.decoder.apply(cursor)
14 26 393 - 522 Apply cats.data.Validated.andThen cats.data.Validated.fromEither[io.circe.DecodingFailure, A](RichValidationDecoder.this.decoder.apply(cursor)).toValidatedNel[io.circe.DecodingFailure, A].andThen[cats.data.NonEmptyList[io.circe.DecodingFailure], B](RichValidationDecoder.this.liftDecodingFailures[B](lift, cursor))
14 11 393 - 522 Apply cats.data.Validated.andThen cats.data.Validated.fromEither[io.circe.DecodingFailure, A](RichValidationDecoder.this.decoder.apply(cursor)).toValidatedNel[io.circe.DecodingFailure, A].andThen[cats.data.NonEmptyList[io.circe.DecodingFailure], B](RichValidationDecoder.this.liftDecodingFailures[B](lift, cursor))
14 16 487 - 521 Apply io.taig.circe.validation.RichValidationDecoder.liftDecodingFailures RichValidationDecoder.this.liftDecodingFailures[B](lift, cursor)
14 1 487 - 521 Apply io.taig.circe.validation.RichValidationDecoder.liftDecodingFailures RichValidationDecoder.this.liftDecodingFailures[B](lift, cursor)
21 17 742 - 756 Select io.circe.ACursor.history cursor.history
21 29 694 - 760 Apply scala.Function1.andThen lift.andThen[cats.data.Validated[cats.data.NonEmptyList[io.circe.DecodingFailure],B]](((x$1: cats.data.ValidatedNel[String,B]) => x$1.leftMap[cats.data.NonEmptyList[io.circe.DecodingFailure]](((x$2: cats.data.NonEmptyList[String]) => x$2.map[io.circe.DecodingFailure](((x$3: String) => io.circe.DecodingFailure.apply(x$3, cursor.history)))))))
21 2 742 - 756 Select io.circe.ACursor.history cursor.history
21 20 707 - 759 Apply cats.data.Validated.leftMap x$1.leftMap[cats.data.NonEmptyList[io.circe.DecodingFailure]](((x$2: cats.data.NonEmptyList[String]) => x$2.map[io.circe.DecodingFailure](((x$3: String) => io.circe.DecodingFailure.apply(x$3, cursor.history)))))
21 5 707 - 759 Apply cats.data.Validated.leftMap x$1.leftMap[cats.data.NonEmptyList[io.circe.DecodingFailure]](((x$2: cats.data.NonEmptyList[String]) => x$2.map[io.circe.DecodingFailure](((x$3: String) => io.circe.DecodingFailure.apply(x$3, cursor.history)))))
21 14 694 - 760 Apply scala.Function1.andThen lift.andThen[cats.data.Validated[cats.data.NonEmptyList[io.circe.DecodingFailure],B]](((x$1: cats.data.ValidatedNel[String,B]) => x$1.leftMap[cats.data.NonEmptyList[io.circe.DecodingFailure]](((x$2: cats.data.NonEmptyList[String]) => x$2.map[io.circe.DecodingFailure](((x$3: String) => io.circe.DecodingFailure.apply(x$3, cursor.history)))))))
21 13 723 - 757 Apply io.circe.DecodingFailure.apply io.circe.DecodingFailure.apply(x$3, cursor.history)
21 22 717 - 758 Apply cats.data.NonEmptyList.map x$2.map[io.circe.DecodingFailure](((x$3: String) => io.circe.DecodingFailure.apply(x$3, cursor.history)))
21 7 717 - 758 Apply cats.data.NonEmptyList.map x$2.map[io.circe.DecodingFailure](((x$3: String) => io.circe.DecodingFailure.apply(x$3, cursor.history)))
21 28 723 - 757 Apply io.circe.DecodingFailure.apply io.circe.DecodingFailure.apply(x$3, cursor.history)