Last active
March 27, 2018 06:20
-
-
Save Laimiux/ffcb6e3641721abab8558feb577b6a30 to your computer and use it in GitHub Desktop.
This file contains 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
fun dataStream( | |
textChangedEvents: Flowable<TextChangedEvent>, | |
submitCommentEvents: Flowable<SubmitCommentEvent> | |
): Flowable<CommentFormData> { | |
// We need to start with something | |
val initialFormState = CommentFormData(comment = "", isCommentValid = false, submitRequest = null) | |
// RxJava scan operator takes initial state and a reduce function | |
// This operator manages the state for us, where it will keep track | |
// of the latest state and provide it for next incoming event | |
return textChangedEvents.scan(initialFormState) { event, currentState -> | |
reduce(event, currentState) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment