Created
July 12, 2010 08:41
-
-
Save pjotrp/472262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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