Skip to content

Instantly share code, notes, and snippets.

@johnswanson
Created April 22, 2014 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnswanson/11166363 to your computer and use it in GitHub Desktop.
Save johnswanson/11166363 to your computer and use it in GitHub Desktop.
(require '[clojure.core.async :as async])
(def c (async/to-chan (range 10)))
(async/<!! (async/filter< even? c)) ;; => 0
(async/<!! (async/filter< even? c)) ;; => 4
(async/<!! (async/filter< even? c)) ;; => 8
(let [c (async/to-chan (range 10)) evens (async/filter< even? c) odds (async/filter< odd? c)]
(printf "first even: %d\nsecond even: %d\n" (async/<!! evens) (async/<!! evens))
(printf "first odd: %d\nsecond odd: %d\n" (async/<!! odds) (async/<!! odds))
(printf "third even: %d\n" (async/<!! evens)))
;; output:
;; first even: 2
;; second even: 4
;; first odd: 3
;; second odd: 7
;; third even: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment