add usage examples for conflate / conflate with seed (#25498)

* +doc conflate and conflateWithSeed docs examples

* fixes

* show throttle in the example so its more obvious that "slow upstream" etc
This commit is contained in:
Konrad `ktoso` Malawski 2018-09-20 16:22:11 +09:00 committed by GitHub
parent 4206e16954
commit bf3c11464e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 112 additions and 18 deletions

View file

@ -26,4 +26,30 @@ object SourceOrFlow {
//#log
}
def conflateExample(): Unit = {
//#conflate
import scala.concurrent.duration._
Source.cycle(() List(1, 10, 100, 1000).iterator)
.throttle(10, per = 1.second) // faster upstream
.conflate((acc, el) acc + el) // acc: Int, el: Int
.throttle(1, per = 1.second) // slow downstream
//#conflate
}
def conflateWithSeedExample(): Unit = {
//#conflateWithSeed
import scala.concurrent.duration._
case class Summed(i: Int) {
def sum(other: Summed) = Summed(this.i + other.i)
}
Source.cycle(() List(1, 10, 100, 1000).iterator)
.throttle(10, per = 1.second) // faster upstream
.conflateWithSeed(el Summed(el))((acc, el) acc sum Summed(el)) // (Summed, Int) => Summed
.throttle(1, per = 1.second) // slow downstream
//#conflateWithSeed
}
}