ListBinding
com.tersesystems.blindsight.jsonld.ListBinding
final case class ListBinding[T](key: BindingKey)(implicit evidence$6: NodeMapper[T]) extends Binding
A binding between a list object and a value.
val listOfStrings = schemaOrg("listOfStrings").bindList[String]
val aListOfStrings = NodeObject(
listOfStrings bind Seq("One", "Two", "Three", "Four")
)
You can resolve elements as null
using an Option
type:
val optionalStrings = schemaOrg("optionalStrings").bindList[Option[String]]
val obj = NodeObject(
optionalStrings bind Seq(
Some("some"),
None,
)
)
You can specify a list object to contain other list objects. For example, using the geometry example:
trait MyGeoContext {
val geojson = IRI("https://purl.org/geojson/vocab#")
val bbox = geojson.term("bbox").bindList[Double]
val geometry = geojson.term("geometry").bindObject[Geometry]
implicit def seqMapper: NodeMapper[Seq[Double]] =
NodeMapper { iter =>
val mapper = implicitly[NodeMapper[Double]]
ListObject(iter.map(mapper.mapNode))
}
val coordinates = vocab.term("coordinates").bindList[Seq[Double]]
}
final case class Geometry(`@type`: String, coords: Seq[Seq[Double]])
object Geometry extends MyGeoContext {
implicit val nodeMapper: NodeObjectMapper[Geometry] = NodeObjectMapper { geo =>
val `@type` = Keyword.`@type`.bindIRI
NodeObject(
`@type` -> geo.`@type`,
coordinates -> geo.coords
)
}
}
val geoFeatureNode = NodeObject(
`@type` -> "Feature",
bbox -> Seq(-10.0, -10.0, 10.0, 10.0),
geometry -> Geometry(
"polygon",
Seq(
Seq(-10.0, -10.0),
Seq(10.0, -10.0),
Seq(10.0, 10.0),
Seq(-10.0, 10.0)
)
)
)
Attributes
- T
the node mapper type class instance
- key
the binding key
- See also:
- Source:
- Binding.scala
- Graph
- Supertypes