Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns lab32)
- (def futureCap 3)
- (defn pfilter [pred coll]
- (let [n 4
- chunked (fn chunked [c]
- (lazy-seq
- (if (not-empty c)
- (cons (take futureCap c) (chunked (drop futureCap c))))))
- fut (fn [c] (map #(future (do (println "fut" %) (doall (filter pred %)))) c))
- step (fn step [[x & xs :as vs] r]
- (lazy-seq
- (if-let [s (seq r)]
- (cons (deref x) (step xs (rest s)))
- (map deref vs)
- )))
- fc (fut (chunked coll))]
- (flatten (step fc (drop n fc)))
- )
- )
- (let [coll `(6 4 5 2 3 2 8 0 3 7 9 11)
- pred (fn [x] (do
- (println (format "lazy%d " x))
- (Thread/sleep 5000)
- (even? x)
- ))
- ]
- (do
- (time (doall (pfilter pred coll)))
- (time (doall (filter pred coll)))
- )
- )
- (shutdown-agents)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement