Skip to content

Instantly share code, notes, and snippets.

@pjotrp
Created July 1, 2010 06:13
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/459640 to your computer and use it in GitHub Desktop.
Save pjotrp/459640 to your computer and use it in GitHub Desktop.
class GapSplitting3Spec extends FlatSpec with ShouldMatchers {
case class Symbol()
case object Gap extends Symbol
case object A extends Symbol
case object G extends Symbol
case object C extends Symbol
case object T extends Symbol
def splitSimplePass3(seq: List[Symbol]): List[List[Symbol]] = {
val gap = Gap
val isGap = (seq(0) == gap)
def isMatch(c : Symbol) = { if (isGap) c == gap else c != gap }
val s = seq.takeWhile{ isMatch }
val tail = seq.takeRight(seq.length - s.length)
tail match {
case Nil => s :: Nil
case _ => s :: splitSimplePass3(tail)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment