Problem using Scalaz ValidationNel and ⊛ with more than 12 checks, maybe Shapeless and HLists can help?

17 views
Skip to first unread message

Andreas Joseph Krogh

unread,
May 30, 2016, 3:10:58 PM5/30/16
to Shapeless Dev
Hi all.

I have this example:

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

Miles Sabin

unread,
May 31, 2016, 2:39:48 AM5/31/16
to shapel...@googlegroups.com
Hi Andreas,

This mailing list is more or less deprecated now. Discussion around
shapeless now happens on its gitter channel,

https://gitter.im/milessabin/shapeless

and there is a shapeless tag on Stackoverflow ... you will find a lot
of people able and willing to help you out in both places :-)

Cheers,


Miles
> --
> You received this message because you are subscribed to the Google Groups
> "Shapeless Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to shapeless-de...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
http://milessabin.com/blog
http://twitter.com/milessabin
Reply all
Reply to author
Forward
0 new messages