项目作者: caleb-allen

项目描述 :
Kotlin reactive streams based on coroutines
高级语言: Kotlin
项目地址: git://github.com/caleb-allen/Konko-Flow.git
创建时间: 2018-03-14T06:17:51Z
项目社区:https://github.com/caleb-allen/Konko-Flow

开源协议:

下载


Konko

Konko is a Kotlin library aiming to give users the power and flexibility of reactive streams but with the benefit of concurrency using Kotlin coroutines. Konko was inspired by Flow for Elixir

Konko-Flow aims to have a similar API to the RxJava equivalent Flowable. Flow is in an early stage and the API is likely to change.

Examples

  1. val a = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  2. Flow.from(a)
  3. .filter { it % 2 == 0 }
  4. // partitions the data flow into multiple streams, on which future operations will run concurrently
  5. .partition()
  6. .map { "$it says hi!" }
  7. .forEach { println(it) }

A more complex example. This generates a map for every word in a text file, and how many time it occurs.

  1. val wordCounts = Flow.from(largeTextFile)
  2. .partition()
  3. .flatMap { it.split(" ") }
  4. .reduceWith({ mutableMapOf<String, Int>() },
  5. { map, item ->
  6. val existing = map.getOrDefault(item, 0)
  7. map[item] = existing + 1
  8. },
  9. { map1, map2 ->
  10. map1.putAll(map2)
  11. }
  12. }
  13. // ["the": 10, "to": 5, etc...]