Clone the above repo and import into your favorite editor.
Eli Jordan
val x = ${expr}
(x, x)
(${expr}, ${expr})
are these programs the same..?
It depends on ${expr}
val x = "hello"
(x, x)
("hello", "hello")
are these programs the same..?
Yes!
val x = println("hello")
(x, x)
(println("hello"), println("hello"))
are these programs the same..?
No!
"the number of objects an average human can hold in short-term memory is 7 ± 2"
- Wikipedia
"the meaning of a complex expression is determined by the meanings of its constituent expressions and the rules used to combine them."
- Wikipedia
val reader = new BufferedReader(
new FileReader("my-file.txt")
)
var line = reader.readLine()
var count = 0
while(line != null) {
val words = line.split("\\s")
words.foreach { w =>
count += 1
}
line = reader.readLine()
}
reader.close()
println(count)
val path = Paths.get("my-file.txt")
readAll[IO](path, blockingEc, 4096)
.through(text.utf8Decode)
.through(text.lines)
.flatMap(s => Stream.emits(s.split("\\s")))
.map(_ => 1)
.fold(0)(_ + _)
.evalMap(c => IO(println(c)))
val path = Paths.get("my-file.txt")
val bytes = readAll[IO](path, blockingEc, 4096)
type Transform[-A, +B] = Pipe[IO, A, B]
val words: Transform[String, String] =
_.flatMap(s => Stream.emits(s.split("\\s")))
val ones: Transform[String, Int] =
_.map(_ => 1)
val sum: Transform[Int, Int] =
_.fold(0)(_ + _)
val print: Transform[Int, Unit] =
_.evalMap(x => IO(println(x)))
bytes
.through(text.utf8Decode)
.through(text.lines)
.through(words)
.through(ones)
.through(sum)
.through(print)
val transforms: Transform[Byte, Unit] =
text.utf8Decode[IO] andThen
text.lines andThen
words andThen
ones andThen
sum andThen
print
bytes.through(transforms)