Created
September 7, 2016 14:10
-
-
Save alexandru/6bbaf7d1a7edef290e17696713ef9e97 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
| sealed trait State { def count: Int } | |
| case class Odd(count: Int) extends State | |
| case class Even(count: Int) extends State | |
| case class Emit(count: Int) extends State | |
| val scanned = | |
| observable.scan(Empty : State) { (state, elem) => | |
| val newState = state match { | |
| case Odd(count) => | |
| val s = if (elem % 2 == 1) Odd(count+1) else Even(1) | |
| case Even(count) => | |
| if (elem % 2 == 0) Even(count+1) else Odd(1) | |
| case Emit(_) => | |
| if (elem % 2 == 0) Even(1) else Odd(1) | |
| } | |
| if (newState.count > 100) | |
| Emit(newState.count) | |
| else | |
| newState | |
| } | |
| scanned.collect { case Emit(n) => true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment