Lazy concatenation of sequence in Clojure -


Here's an introductory question: Is there no way to unite sequential sequences in a way in the closure? I know the macro, but I can not think of its correct application for the sequences of a indexed number.

My use is sluggish loading data from an API through paged (offset / limited) requests. Each request executed through I request-fn gets 100 results:

  (Request request -fn (repeated (partial + 100) 0))  

When there are no further results, then request -fn gives an empty sequence this happens when I stop running:

  (Seek during move (Map request - F. For example, the API can return up to 500 results and it can be fun:  
  Code> (defn request -fn [offset] (when (& lt; offset 500) (offset list))  

If I want to add results, then I (concat I can use the result), but he eagerly evaluates the result sequence:

  (Apply contact (Lake-Second Sec (map request- FN (Rep Avritt (partial + 100) 0))))  

what lazy cat or anything else?

For the record, apply only consume sufficient quantity of logic sequences Because it needs to determine which edges call for the given function. Since the maximum number of concat 3, apply , the maximum number of items will be realized from the underlying sequence.

If those API calls are expensive and you can not really create unnecessary people, then you will need a function that accepts a seq-of-seqs and lazes them together at one time Connects I do not think there is anything inherent in it, but it is quite simple to write your own:

  (lazy-seq (if (seq colls) (ConSat (first calls) (lazy-cat ') (Next calls))))  

Comments