Skip to content

Instantly share code, notes, and snippets.

@pjotrp
Created July 12, 2010 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjotrp/472262 to your computer and use it in GitHub Desktop.
Save pjotrp/472262 to your computer and use it in GitHub Desktop.
case class Symbol()
case object Gap extends Symbol
case class Nucleotide() extends Symbol
case object GapN extends Nucleotide
case object A extends Nucleotide
case object G extends Nucleotide
case object C extends Nucleotide
case object T extends Nucleotide
class Splitter7[T] {
def splitSimplePass7(seq: List[T]): List[List[T]] = {
// fails: def isGapType(c : T) = {
def isGapType[Q <: T](c : Q) = {
c match {
case Gap => true
case GapN => true
case _ => false
}
}
val isGap = isGapType(seq(0))
def isMatch(c : T) = { if (isGap) isGapType(c) else !isGapType(c) }
val s = seq.takeWhile{ isMatch }
val tail = seq.takeRight(seq.length - s.length)
tail match {
case Nil => s :: Nil
case _ => s :: splitSimplePass7(tail)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment