ClojureDocs

导航

命名空间

chunk

  • (chunk b)
无文档
2 Examples
(chunk-rest
 (chunk-cons (chunk (chunk-buffer 32))
             (seq (range 42))))

;; => (32 33 34 35 36 37 38 39 40 41)

;; Or if you'd prefer to read it threaded:
(-> (chunk-buffer 32)
    (chunk)
    (chunk-cons (seq (range 42)))
    (chunk-rest))

;; => (32 33 34 35 36 37 38 39 40 41)
;; re-chunk takes a sequence (already chunked or not)
;; and produces another sequence with different chunking size.

(defn re-chunk [n xs]
  (lazy-seq
    (when-let [s (seq (take n xs))]
      (let [cb (chunk-buffer n)]
        (doseq [x s] (chunk-append cb x))
        (chunk-cons (chunk cb) (re-chunk n (drop n xs)))))))

(def s (pmap f (re-chunk 1000 (range 1000)))) ; a 1000+ concurrent threads pmap

(def s (map #(println %) (re-chunk 3 (range 50)))) ; chunk-size = 3

(first s) ; moves ahead 3 on first access
;; 0
;; 1
;; 2

(second s) ; already cached
nil

(first (drop 3 s)) ; 3 more
;; 3
;; 4
;; 5
0 Notes
No notes for chunk