Last active
August 19, 2022 06:52
-
-
Save koen-dejonghe/eb721125d28871e47ce0a1ff9c51ec30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class SomeEvent(value: Long) | |
val events = Source | |
.tick(0 seconds, 250 millis, "") | |
.zipWithIndex | |
.map { case (_, l) => | |
SomeEvent(l) | |
} | |
val group = Flow[SomeEvent].groupedWithin(100, 500 millis) // +/- 2 events per group | |
val slide = Flow[Seq[SomeEvent]].sliding(3, 1) // 3 groups per slide, step size = 1 | |
val exe = events | |
.via(group) | |
.via(slide) | |
.map(_.flatten) | |
.runWith(Sink.foreach(println)) | |
try Await.result(exe, 6 seconds) | |
catch { case _: Throwable => } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will generate something like this:
If you leave the
.map(_.flatten)
out, then you can still see the individual groups. For example: