Last active
August 29, 2015 13:57
-
-
Save NightRa/9415625 to your computer and use it in GitHub Desktop.
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 characters
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