validation.Field.scala Maven / Gradle / Ivy
package jap
package validation
import scala.language.experimental.macros
import scala.util.Try
case class Field[P](
path: FieldPath,
value: P,
) {
val name = path.name
val fullPath = path.full
def subField[S](name: String, value: S): Field[S] = Field(path + name, value)
def named(name: String): Field[P] = copy(path = path.named(name))
def withPath(path: FieldPath): Field[P] = copy(path = path)
def withValue[V](value: V): Field[V] = copy(value = value)
def map[B](f: P => B): Field[B] = withValue(f(value))
def mapPath(f: FieldPath => FieldPath): Field[P] = withPath(f(this.path))
override def toString = fullPath + ":" + value
}
object Field {
implicit def toPath[P](f: Field[P]): FieldPath = f.path
def apply[P](value: P): Field[P] = Field(FieldPath.root, value)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy