Last active
August 29, 2015 13:57
-
-
Save NightRa/9415625 to your computer and use it in GitHub Desktop.
Revisions
-
NightRa renamed this gist
Mar 7, 2014 . 1 changed file with 3 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,15 @@ 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 -
Matt Muscari created this gist
Mar 7, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ trait Decorable[A, B <: Decorator] { def decorate(obj: A, dec: B): Either[String, A] } object Decorator { def decorate[A, B <: Decorator](obj: A, dec: B)(implicit d: Decorable[A,B]) = { d.decorate(obj, dec) } } abstract class Decorator { } object TagsDecorator { implicit object DecorableClick extends Decorable[Click, TagsDecorator] { override def decorate[B <: TagsDecorator](obj: Click, dec: B) = { 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._ }