Skip to content

Instantly share code, notes, and snippets.

@stanpalatnik
Created December 20, 2014 19:22
Show Gist options
  • Save stanpalatnik/c49b0f434107f6227ba8 to your computer and use it in GitHub Desktop.
Save stanpalatnik/c49b0f434107f6227ba8 to your computer and use it in GitHub Desktop.
case class Summary(results: IndexedSeq[Sentence]) extends Traversable[String] {
lazy val charCount = if (results.isEmpty) 0 else results.map(_.sentence.size).sum
def foreach[U](f: String => U) {
results.foreach( s => f(s.sentence) )
}
def takeChars(limitCharCount: Int): Summary = {
var count = 0
val newSentences = results.takeWhile { sentence =>
count += sentence.sentence.size
limitCharCount >= count
}
Summary(newSentences)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment