Partition a seq by a "windowing" predicate in Clojure -
I would like to divide a seq into subseqs, in the same way, according to the partition, the function is not implemented The person element, but for many elements.
For example:
(gather (FN [ab] (> (- BA) 2)) [1 4 5 8 9 10 15 20 21 ]) will result in:
[[1] [4 5] [8 9 10] [15] [20 21]] Similarly:
(defn f [ab] (> (- BA) 2)) (F [1 2 3 4]) ;; = & Gt; [[1 2 3] [4]] (gathering f [1 2 3 4 5 6 7 8 9]) ;; = & Gt; [[1 2 3] [4 5 6] [7 8 9]] This is the idea that I apply the beginning of the list and the next element of the function, and if the function returns True, we split the current head of the list into a new partition till that point. I have written it:
(defn collect [pred? Lst] (loop [ab] [l] [l] (let's [first (a) (First L) NXT (CONJR BR) RST (rest L)] (What is CONSIDED (empty? L) (blank) (again ACC NXT RST) ((Prepaid Pre?) AB (Repeat RIC NCT RSIR): Other (Cause ACC) [B] RST)))) And it works, but I know that there is a simple way. My question is:
Is the function designed to do this, where this function will be unnecessary? If not, is there any other idiotic (or simple) solution that I have ignored?
Thanks
The basic explanation of the question
We ( All) understand your question incorrectly because whenever the continuous elements are held, then you want to start a new division.
Nevertheless, the lazy, created on the partition - (
(split-between (fn [ab] ( & Gt; (- BA) 2)) [1 4 5 8 9 10 15 20 21]); & gt; (1) (4-5) (8910) (15) (20 21)) The real question
The real question asks us to start a new one whenever pred? Contains for current partition start and for the current element. For this we can remove our source with some changes, by partition-by . (defn collect [pred? Coll] (lazy-seq (go ahead (let's go first) (first time FST (Lenaphst #) (while charging # ((Pre-paid?) FST% ) ();) (Opposition Runs (Collected Before (CEC) (& gt; (- BA) 2)) () () 1 4 5 8 9 10 15 20 21]); & gt; (1) (4 5) (8 9 10) (15) (20 21)) (assembled (FN [AB] (> (- BA) 2)) [1 2 3 4]) => ( 1 2 3) (4)) (assembled (Fn [ab] (> (- BA) 2)) [1 2 3 4 5 6 7 8 9]); = & gt; ((1 2 3 ) (4 5 6) (7 89))
Comments
Post a Comment