This file contains hidden or 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
import scalaz._ | |
import Scalaz._ | |
def charLineCount[T[_]:Traverse](t: T[Char]) = | |
t.traverse[({type λ[x] = State[(Int, Int),x]})#λ, (Int, Int)](a => | |
state((counts: (Int, Int)) => | |
((counts._1 + 1, counts._2 + (if (a == '\n') 1 else 0)), (counts._1, counts._2)))) ! (1,1) | |
println(charLineCount("the cat in the hat\n sat on the mat\n".toList).last) // (35, 2) |