Created
December 20, 2014 19:22
-
-
Save stanpalatnik/c49b0f434107f6227ba8 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 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