I would like to add additional method for Squeryl Record (Lift web framework). The method is named validateTry. See the code below
import scala.language.postfixOps
import scala.util._
import net.liftweb.record._
package object code {
implicit class RecordOps[T <: Record[T]](r: T) {
def validateTry(): Try[T] = {
r.validate match {
case Nil => Success(r)
case errs => Failure(new Exception("Error(s) during validation " + r.getClass() + ": " + errs.mkString(", ")))
}
}
}
}
and it works as expected. But I would like to extend AnyVal, like this
implicit class RecordOps[T <: Record[T]](r: T) extends AnyVal {
because as I see it will be "right" (as I see it should have influence on performance). But after I have added "extends AnyVal", I received error "value class needs to have exactly one public val parameter". What is this and how to fix? (And do I really need to fix?)
Thanks.
UPD. I added "val" to constructor definition and it started work. Thanks to the link Vasya Novikov gave me. Right peace of code looks like this:
implicit class RecordOps[T <: Record[T]](val r: T) extends AnyVal {
And it works as expected. Documentation says it should avoid instantiation of class as I see. The link is http://docs.scala-lang.org/overviews/core/value-classes.html