
octopus.FieldPath.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of octopus_sjs0.6_2.13 Show documentation
Show all versions of octopus_sjs0.6_2.13 Show documentation
Boilerplate-free validation library for Scala
The newest version!
package octopus
sealed trait PathElement extends Any with Serializable{
def asString: String
}
case class FieldLabel(label: Symbol) extends AnyVal with PathElement {
def asString: String = label.name
}
case class CollectionIndex(index: Int) extends AnyVal with PathElement {
def asString: String = s"[$index]"
}
case class MapKey(key: String) extends AnyVal with PathElement {
def asString: String = s"[$key]"
}
case class FieldPath(parts: List[PathElement]) extends AnyVal with Serializable {
def ::(element: PathElement): FieldPath =
copy(element :: parts)
def asString: String = {
if(parts.isEmpty) {
""
} else {
parts.tail.foldLeft(parts.head.asString) {
case (buff, element: FieldLabel) =>
s"$buff.${element.asString}"
case (buff, element) =>
buff + element.asString
}
}
}
}
object FieldPath extends Serializable {
val empty = FieldPath(Nil)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy