Last active
August 29, 2015 14:08
-
-
Save wheaties/3567607f1fdfbfc3c52d to your computer and use it in GitHub Desktop.
Is Impls
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
trait IsBase[F]{ | |
type T | |
type W[X] | |
def to(f: F): W[T] | |
def from(wt: W[T]): F | |
def apply(f: F): W[T] = to(f) | |
} |
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
trait IsFuture[F] extends IsBase[F]{ | |
type W[X] = Future[X] | |
} | |
object IsFuture{ | |
def unapply[F](f: F)(implicit isf: IsFuture[F]): Option[Future[isf.T]] = Some(isf(f)) | |
def apply[F](implicit isf: IsFuture[F]): Aux[F, isf.T] = isf | |
type Aux[FA, A] = IsFuture[FA]{ type T = A } | |
implicit def mk[A] = new IsFuture[Future[A]]{ | |
type T = A | |
def from(wt: W[T]) = wt | |
def to(f: Future[A]) = f | |
} | |
} |
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
trait IsTry[F] extends IsBase[F]{ | |
type W[X] = Try[X] | |
} | |
object IsTry{ | |
def unapply[F](f: F)(implicit ist: IsTry[F]): Option[Try[ist.T]] = Some(ist(f)) | |
def apply[F](implicit ist: IsTry[F]): Aux[F, ist.T] = ist | |
type Aux[FA, A] = IsTry[FA]{ type T = A } | |
implicit def mk[A] = new IsTry[Try[A]]{ | |
type T = A | |
def from(wt: W[T]) = wt | |
def to(f: F) = f | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment