Skip to content

Instantly share code, notes, and snippets.

@trane
Last active December 10, 2016 03:22
Show Gist options
  • Save trane/ff512d6d1c7254264b81bbb2d613f156 to your computer and use it in GitHub Desktop.
Save trane/ff512d6d1c7254264b81bbb2d613f156 to your computer and use it in GitHub Desktop.
import scala.util.Try
object ImplementedClient {
def getStuff[A](url: String): Try[A] =
Try(url.asInstanceOf[A])
}
trait Client[F[_], G[_]] {
def transform[A](f: F[A]): G[A]
def get[A](url: String): G[A]
}
trait BaseClient[G[_]] extends Client[Try, G] {
def transform[A](f: Try[A]): G[A]
def get[A](url: String): G[A] = transform(ImplementedClient.getStuff[A](url))
}
val optionClient = new BaseClient[Option] { def transform[A](f: Try[A]): Option[A] = f.toOption }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment