Created
January 31, 2015 20:27
-
-
Save wheaties/b7bff5f42209b5807725 to your computer and use it in GitHub Desktop.
Compilation error
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
/* | |
So here's the error which seems to be straight forward. That said, I've tried a bunch of things and this is the "bets" I've been | |
able to do: | |
[error] CKnot.scala:18: Cannot construct a collection of type That with elements of type B based on a collection of type C[A]. | |
[error] def apply[A, C[A] <: GenTraversableLike[A, C[A]]](ma: C[A], f: A => C[B]) = ma flatMap f | |
[error] | |
[error] CKnot.scala:26: Cannot construct a collection of type That with elements of type B based on a collection of type C[A]. | |
[error] a <- ma | |
[error] | |
...and it continues | |
*/ | |
import scala.collection.{GenTraversable, GenTraversableLike} | |
trait CKnot[C[+_], B]{ | |
type R | |
def apply[A](ma: C[A], f: A => B): C[R] | |
} | |
trait CKnotCompanion extends LowPriorityCKnot{ | |
def apply[B](implicit knot: CKnot[C, B]): Aux[C, B, knot.R] = knot | |
implicit def Cbase[B]: Aux[C, C[B], B] = | |
new CKnot[C, C[B]]{ | |
type R = B | |
def apply[A](ma: C[A], f: A => C[B]) = ma flatMap f | |
} | |
implicit def opt[B]: Aux[C, Option[B], B] = | |
new CKnot[C, Option[B]]{ | |
type R = B | |
def apply[A](ma: C[A], f: A => Option[B]) = for{ | |
a <- ma | |
v <- f(a) | |
} yield v | |
} | |
} | |
trait LowPriorityCKnot extends LowestPriorityCKnot{ | |
implicit def trav[C0[_] <: GenTraversable[_],B]: Aux[C, C0[B], C[B]] = | |
new CKnot[C, C0[B]]{ | |
type R = C0[B] | |
def apply[A](ma: C[A], f: A => C0[B]) = (ma map f) filter (_.nonEmpty) | |
} | |
} | |
trait LowestPriorityCKnot{ | |
type C[X] <: GenTraversableLike[X, C[X]] | |
type Aux[G[_], B, R0] = CKnot[G, B]{ type R = R0 } | |
implicit def any[B]: Aux[C, B, B] = | |
new CKnot[C, B]{ | |
type R = B | |
def apply[A](ma: C[A], f: A => B) = ma map f | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment