Hi all.
import org.joda.time.LocalDate
import scalaz.Scalaz._
import scalaz._
case class Comp(name: String)
case class Inv(invoiceNumber: Option[String], sentDate: Option[LocalDate], company: Option[Comp])
class ValidationTest {
def checkInvoiceNumber(invoice: Inv) : ValidationNel[String, String] = invoice.invoiceNumber match {
case Some(v) => v.successNel
case None => "Missing invoice-number".failureNel
}
def checkSentDate(invoice: Inv) : ValidationNel[String, LocalDate] = invoice.sentDate match {
case Some(v) => v.successNel
case None => "Missing invoice-date".failureNel
}
def checkCompany(invoice: Inv): ValidationNel[String, Comp] = invoice.company match {
case Some(v) => v.successNel
case None => "Missing company".failureNel
}
def validate(): Unit = {
val invoice = Inv("aaaaaa".some, LocalDate.now().some, Option.empty[Comp])
(checkInvoiceNumber(invoice)
⊛ checkSentDate(invoice)
⊛ checkCompany(invoice)
).tupled match {
case Failure(msgList) =>
case Success((invoiceNumber, sentDate, company)) =>
}
}
}
The problem occurs when I have more than 12 checks.
I've searched the net and found some examples using shapeless-scalaz, but cannot make it work the way I want, like above. That is preserving the types in Success.
Any examples using recent version of Shapless would be a huge help.
Thanks.
--
Andreas