Skip to content

Instantly share code, notes, and snippets.

@shadaj
Created September 21, 2014 00:43
Show Gist options
  • Save shadaj/c7b2a00e1245f603516b to your computer and use it in GitHub Desktop.
Save shadaj/c7b2a00e1245f603516b to your computer and use it in GitHub Desktop.
object Example {
import scala.collection.IndexedSeqLike
trait BaseLike
class DNABase extends BaseLike
trait BioSequence[B <: BaseLike] extends IndexedSeq[B]
class DNA extends BioSequence[DNABase] with IndexedSeqLike[DNABase, DNA] {
override def newBuilder = ???
def length = 1
def apply(idx: Int) = {
new DNABase
}
}
val myDNA = new DNA
val droppedDNA: DNA = myDNA.drop(1) // Compiles because DNA extends IndexedSeqLike
def processSequence[B <: BaseLike, C <: BioSequence[B]](seq: C): C = {
seq.drop(1) // Doesn't compile because BioSequence doesn't extend IndexedSeqLike
}
}
object ScalaJSExample extends js.JSApp {
def main() = {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment