Skip to content

Instantly share code, notes, and snippets.

@pjotrp
Created July 3, 2010 09:15
Show Gist options
  • Save pjotrp/462444 to your computer and use it in GitHub Desktop.
Save pjotrp/462444 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
case object AnyGap
def splitSimplePass6[T >: Symbol](seq: List[T]): List[List[T]] = {
def isGapType(c : T) = {
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 :: splitSimplePass6(tail)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment