Skip to content

Instantly share code, notes, and snippets.

@jastice
Created August 28, 2013 14:15
Show Gist options
  • Save jastice/6366493 to your computer and use it in GitHub Desktop.
Save jastice/6366493 to your computer and use it in GitHub Desktop.
object Attribute {
case class Attributed[Thing, Attribute](val thing: Thing, val attributes: Set[Attribute] = Set[Attribute]()) {
/** Add an attribute. */
def +(a: Attribute) = copy(attributes = attributes+a)
/** Change attributes for which the partial function is defined. */
def change(pf: PartialFunction[Attribute,Attribute]) =
new Attributed(thing, attributes.map { pf orElse {case v => v} })
}
val as1 = Attributed[String,String]("rofl")
val as2 = as1 + "silly" + "funny" + "derp"
val as3 = as2 change { case "derp" => "herp" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment