Created
August 28, 2013 14:15
-
-
Save jastice/6366493 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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