def read()

in app/com/gu/memsub/subsv2/reads/ChargeListReads.scala [23:35]


  def read(cat: PlanChargeMap, charge: ZuoraCharge): ValidationNel[String, A]

  // only read if the result is the given type
  def filter[B <: A : ClassTag]: ChargeReads[B] = {
    val requiredClass = implicitly[ClassTag[B]].runtimeClass
    new ChargeReads[B] {
      override def read(cat: PlanChargeMap, charge: ZuoraCharge): ValidationNel[String, B] =
        ChargeReads.this.read(cat, charge).flatMap {
          case b: B if requiredClass.isInstance(b) => Success(b)
          case actual => Failure(s"expected $requiredClass but was $actual").toValidationNel
        }
    }
  }