The following sections have a few exercises for you.
Extend our current EventStream
implementation to include a function called take
. It works much like Clojure's core take
function for sequences: it will take n
items from the underlying event stream after which it will stop emitting items.
A sample interaction, which takes the first five items emitted from the original event stream, is shown here:
(def es1 (from-interval 500)) (def take-es (take es1 5)) (subscribe take-es #(prn "Take values: " %)) ;; "Take values: " 0 ;; "Take values: " 1 ;; "Take values: " 2 ;; "Take values: " 3 ;; "Take values: " 4