Skip to content

Instantly share code, notes, and snippets.

@halcat0x15a
Forked from nisshiee/App.scala
Created June 1, 2012 00:05
Show Gist options
  • Save halcat0x15a/2847387 to your computer and use it in GitHub Desktop.
Save halcat0x15a/2847387 to your computer and use it in GitHub Desktop.
ReaderをIterateeで扱う
import java.io.{ Reader, FileReader }
import scalaz._, Scalaz._
import effect._, IO._
import iteratee._, Iteratee._
object App extends SafeApp{
val separator = sys.props("line.separator").head
override def run(args: ImmutableArray[String]): IO[Unit] = {
val r = new FileReader("test2.txt")
byEnumerator(r)
}
type IEOC = IoExceptionOr[Char]
def byEnumerator(r: Reader): IO[Unit] = {
val lineIter = takeWhile[IEOC, Stream](_ map (_ =/= separator) valueOr false) map (_.length)
val iter = repeatBuild[IEOC, Int, Stream](lineIter).up[IO] map (_.sum)
val enum = enumReader(r)
val read = iter &= enum
(read.run >>= putOut) >> putStrLn("")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment