Skip to content

Instantly share code, notes, and snippets.

@NightRa
Last active August 29, 2015 13:57
Show Gist options
  • Save NightRa/9415625 to your computer and use it in GitHub Desktop.
Save NightRa/9415625 to your computer and use it in GitHub Desktop.
trait Decorable[A, B] {
def decorate(obj: A, dec: B): Either[String, A]
}
object Decorator {
def decorate[A, B](implicit d: Decorable[A,B]) = d
}
object TagsDecorator {
implicit object DecorableClick extends Decorable[Click, TagsDecorator] {
override def decorate(obj: Click, dec: TagsDecorator) = {
Try(Right(obj.copy(tags = dec.getTagsForCid(obj.dst_cid)))).recover {
case e: Throwable => Left(e.getMessage)
}.get
}
}
}
class TagsDecorator extends Decorator {
def getTagsForCid(cid: Long): List[String] = {
List("f")
}
}
case class A {}
object Main {
val b: TagsDecorator = new TagsDecorator
import TagsDecorator._
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment