Review fixes: partition+concat in 10-seq, delete dead defns, dedupe de-duplicated
1. partition + concat added to 10-seq.clj (ported from CLJS core.cljs) 2. Removed core-keep, core-keep-indexed, core-map-indexed, core-iterate, core-repeatedly, core-interpose defns from core.janet (bindings already removed in prior commit, left dead bodies) 3. Removed dedupe from 40-lazy.clj (belongs in 20-coll.clj) Gates: lazy-infinite 22/22, conformance 229x3, specs 32/32
This commit is contained in:
parent
1ed03e578f
commit
4a2ef99fee
3 changed files with 31 additions and 86 deletions
|
|
@ -34,3 +34,34 @@
|
|||
run (cons fst (take-while (fn [x] (= fv (f x))) (rest s)))]
|
||||
(cons run (step (lazy-seq (drop (count run) s)))))))))]
|
||||
(step coll)))
|
||||
|
||||
;; Lazy partition: yields complete partitions of size n. Optional step.
|
||||
;; Ported from CLJS core.cljs (no chunked-seq branches).
|
||||
(defn partition
|
||||
([n coll] (partition n n coll))
|
||||
([n step coll]
|
||||
(lazy-seq
|
||||
(when-let [s (seq coll)]
|
||||
(let [p (take n s)]
|
||||
(when (= n (count p))
|
||||
(cons p (partition n step (nthrest coll step)))))))))
|
||||
|
||||
;; Lazy concat: concatenates colls lazily. Ported from CLJS core.cljs.
|
||||
(defn concat
|
||||
([] (lazy-seq nil))
|
||||
([x] (lazy-seq x))
|
||||
([x y]
|
||||
(lazy-seq
|
||||
(let [s (seq x)]
|
||||
(if s
|
||||
(cons (first s) (concat (rest s) y))
|
||||
y))))
|
||||
([x y & zs]
|
||||
(let [step (fn step [xys zs]
|
||||
(lazy-seq
|
||||
(let [xys (seq xys)]
|
||||
(if xys
|
||||
(cons (first xys) (step (rest xys) zs))
|
||||
(when zs
|
||||
(step (first zs) (next zs)))))))]
|
||||
(step (concat x y) zs))))
|
||||
|
|
|
|||
|
|
@ -15,20 +15,6 @@
|
|||
xs seen)))]
|
||||
(step coll #{})))
|
||||
|
||||
;; --- dedupe (lazy, canonical) ---
|
||||
(defn dedupe [coll]
|
||||
(let [step (fn step [s prev]
|
||||
(lazy-seq
|
||||
(let [s (seq s)]
|
||||
(when s
|
||||
(let [x (first s)]
|
||||
(if (= x prev)
|
||||
(step (rest s) prev)
|
||||
(cons x (step (rest s) x))))))))]
|
||||
(let [s (seq coll)]
|
||||
(if s
|
||||
(lazy-seq (cons (first s) (step (rest s) (first s))))
|
||||
()))))
|
||||
|
||||
;; --- keep ---
|
||||
(defn keep
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue