Skip to content

Instantly share code, notes, and snippets.

@benjchristensen
Last active December 11, 2015 23:28
Show Gist options
  • Save benjchristensen/4676533 to your computer and use it in GitHub Desktop.
Save benjchristensen/4676533 to your computer and use it in GitHub Desktop.
Simple example of applying Rx operators to an asynchronous Observable sequence.
(defn simpleComposition []
"Asynchronously calls 'customObservableNonBlocking' and defines a
chain of operators to apply to the callback sequence."
(->
; 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 #(str % "_transformed"))
; subscribe to the sequence and print each transformed String
(.subscribe #(println "onNext =>" %))))
; 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