Last active
December 11, 2015 23:28
-
-
Save benjchristensen/4676544 to your computer and use it in GitHub Desktop.
Simple example of applying Rx operators to an asynchronous Observable sequence.
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
/** | |
* Asynchronously calls 'customObservableNonBlocking' and defines | |
* a chain of operators to apply to the callback sequence. | |
*/ | |
def simpleComposition() { | |
// fetch an asynchronous Observable<String> | |
// that emits 75 Strings of 'anotherValue_#' | |
customObservableNonBlocking() | |
// skip the first 10 | |
.skip(10) | |
// take the next 5 | |
.take(5) | |
// transform each String with the provided function | |
.map({ stringValue -> return stringValue + "_transformed"}) | |
// subscribe to the sequence and print each transformed String | |
.subscribe({ println "onNext => " + it}) | |
} | |
// output | |
onNext => anotherValue_10_transformed | |
onNext => anotherValue_11_transformed | |
onNext => anotherValue_12_transformed | |
onNext => anotherValue_13_transformed | |
onNext => anotherValue_14_transformed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line 14 could be simplified to