run(input: Iterator[Char]): (Int, Int, Int) = 2 // wordsAndSkipped: Iterator[Char] => Iterator[(Int, String)] 3 runMonoid(step)(wordsAndSkipped(input)) 4 5 def runMonoid[M: Monoid]( 6 f: (Int, String) => M 7 )(input: Iterator[(Int, String)]): M = 8 Monoid[M].combineAll(input.map(f.tupled)) 9 10 def step(skip: Int, w: String): (Int, Int, Int) = 11 (countLines(w), countWords(w), countChars(skip, w)) 12 13 def countChars(skip: Int, w: String): Int = skip + w.length 14 15 def countWords(w: String): Int = 1 16 17 def countLines(w: String): Int = 0 // damn... Markus Hauck (@markus1189) Beautiful Composition 31