Created
March 26, 2019 10:33
-
-
Save lrytz/fe09791208969f07e211c5c8601db125 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 annotation.unchecked.uncheckedVariance | |
trait Builder[-A, +To] | |
trait IterableFactory[+CC[_]] { | |
def from[A](source: It[A]): CC[A] | |
def newBuilder[A]: Builder[A, CC[A]] | |
} | |
trait ItOps[+A, +CC[_], +C] { | |
protected type IterableCC[X] = CC[X] @uncheckedVariance | |
protected type IterableC = C @uncheckedVariance | |
protected def newSpecificBuilder: Builder[A @uncheckedVariance, IterableC] | |
protected def fromSpecific(coll: It[A @uncheckedVariance]): IterableC | |
def iterableFactory: IterableFactory[IterableCC] | |
def foo: C = fromSpecific(null) | |
} | |
trait It[+A] extends ItOps[A, It, It[A]] { | |
protected def fromSpecific(coll: It[A @uncheckedVariance]): IterableC = iterableFactory.from(coll) | |
protected def newSpecificBuilder: Builder[A @uncheckedVariance, IterableC] = iterableFactory.newBuilder[A] | |
def iterableFactory: IterableFactory[IterableCC] = It | |
} | |
object It extends IterableFactory[It] { | |
def from[A](source: It[A]): It[A] = new It[A]{} | |
def newBuilder[A]: Builder[A,It[A]] = new Builder[A, It[A]]{} | |
} | |
trait SqOps[A, +CC[_], +C] extends ItOps[A, CC, C] | |
trait Sq[A] extends It[A] with SqOps[A, Sq, Sq[A]] { | |
def flup = 0 | |
} | |
object Test { | |
def main(args: Array[String]): Unit = { | |
val sq = new Sq[String] { } | |
sq.foo.flup | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment