Attributed, attaches attributes to arbitrary data

This commit is contained in:
Mark Harrah 2010-09-17 20:46:31 -04:00
parent b033bc889d
commit ccb3a840c6
1 changed files with 9 additions and 0 deletions

View File

@ -53,4 +53,13 @@ private class BasicAttributeMap(private val backing: Map[AttributeKey[_], Any])
final case class AttributeEntry[T](a: AttributeKey[T], b: T)
{
override def toString = a.label + ": " + b
}
final case class Attributed[D](data: D)(val metadata: AttributeMap)
{
def put[T](key: AttributeKey[T], value: T): Attributed[D] = Attributed(data)(metadata.put(key, value))
}
object Attributed
{
implicit def blank[T](data: T): Attributed[T] = Attributed(data)(AttributeMap.empty)
}