Since Kotlin already has: - `producers` (think: ...
# coroutines
v
Since Kotlin already has: -
producers
(think: sources), -
actors
(=sinks) and -
Channels
(=edges), Throw in: -
transforms
and -
pipes
for easy hookup we end up with
DAGs
, not unlike NodeJS’ streams. Here’s an early proof of concept: https://github.com/venkatperi/kotlin-coroutines-lib/blob/master/src/main/kotlin/com/vperi/kotlinx/coroutines/experimental/TransformChannel.kt
Copy code
runBlocking {
      FS.createReader(inputFile.toPath())
        .pipe(decodeUtf8())
        .pipe(splitLines())
        .pipe(spy({ println("> $it") }))
        .pipe(contents({
          assertEquals(lines.size, it.size)
        }))
    }
where:
Copy code
// doesn't handle lines split across buffers
fun splitLines() = transform<String, String> {
  var count = 0
  input.consumeEach {
    it.split("\n").forEach {
      output.send("${count++}: $it")
    }
  }
}
More in the tests…