Created
November 2, 2016 14:49
-
-
Save timjstewart/74d0cbf3f7e82db759b1bb5ef3f10797 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
import scala.util.Try | |
trait Show[T] { | |
def shows(t: T): Try[String] | |
} | |
trait ShowProtocol { | |
implicit val showAccount: Show[Account] | |
implicit val showCustomer: Show[Customer] | |
} | |
trait DomainShowProtocol extends ShowProtocol { | |
override implicit val showAccount: Show[Account] = (t: Account) => Try("Account") | |
override implicit val showCustomer: Show[Customer] = (t: Customer) => Try("Customer") | |
} | |
case class Account() | |
case class Customer() | |
object Reporting { | |
def report[T: Show](as: Seq[T]): Seq[Try[String]] = as.map(implicitly[Show[T]].shows _) | |
} | |
object DomainShowProtocol extends DomainShowProtocol | |
object Main { | |
def main(args: Array[String]): Unit = { | |
import DomainShowProtocol._ | |
val accts: Seq[Account] = Seq( | |
Account(), | |
Account(), | |
Account() | |
) | |
Reporting.report(accts).foreach(println _) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment