 (defn simpleComposition []
   "Asynchronously calls 'customObservableNonBlocking' and defines
    a chain of operators to apply to the callback sequence."
-  (-> 
+  (->
     (customObservableNonBlocking)
     (.skip 10)
     (.take 5)

      (Observable/noOpSubscription))))

; To see output
#_(.subscribe (customObservableBlocking) #(println %))

(defn customObservableNonBlocking []
  "This example shows a custom Observable that does not block 
   when subscribed to as it spawns a separate thread.
   
  returns Observable<String>"
  (Observable/create 
    (fn [observer]
      (let [f (future 
                (doseq [x (range 50)] (-> observer (.onNext (str "anotherValue_" x))))
                ; after sending all values we complete the sequence
                (-> observer .onCompleted))
            ; a subscription that cancels the future if unsubscribed
            subscription (Observable/createSubscription #(-> f (.cancel true)))]
        ))
      ))

; To see output
#_(.subscribe (customObservableNonBlocking) #(println %))


(defn fetchWikipediaArticleAsynchronously [wikipediaArticleNames]
  "Fetch a list of Wikipedia articles asynchronously.
  
   return Observable<String> of HTML"
  (Observable/create 
    (fn [observer]
      (let [f (future
                (doseq [articleName wikipediaArticleNames]
                  (-> observer (.onNext (http/get (str "http://en.wikipedia.org/wiki/" articleName)))))
                ; after sending response to onnext we complete the sequence
                (-> observer .onCompleted))
            ; a subscription that cancels the future if unsubscribed
            subscription (Observable/createSubscription #(-> f (.cancel true)))]
        ))))

; To see output
#_(-> (fetchWikipediaArticleAsynchronously ["Tiger" "Elephant"]) 
  (.subscribe #(println "--- Article ---\n" (subs (:body %) 0 125) "...")))


; --------------------------------------------------

    (.subscribe #(println "onNext =>" %))))

; To see output
(comment
  (simpleComposition))


; --------------------------------------------------
