Skip to content

Instantly share code, notes, and snippets.

@pjotrp
Created July 2, 2010 07:46
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/461066 to your computer and use it in GitHub Desktop.
Save pjotrp/461066 to your computer and use it in GitHub Desktop.
case class Symbol() {
def isGap() = false
}
case object Gap extends Symbol {
override def isGap() = true
}
case class Nucleotide() extends Symbol
case object GapN extends Nucleotide {
override def isGap() = true
}
case object A extends Nucleotide
case object G extends Nucleotide
case object C extends Nucleotide
case object T extends Nucleotide
def splitSimplePass5(seq: List[Symbol]): List[List[Symbol]] = {
def isGapType(c : Symbol) = c.isGap()
val isGap = isGapType(seq(0))
def isMatch(c : Symbol) = { 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 :: splitSimplePass5(tail)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment