core: move dedupe + seq-to-map-for-destructuring to overlay (+ tests)
Eighth pure-fn batch (jolt-1j0 phase 2), 2 leaf fns. dedupe is eager consecutive
dedup (no transducer arity, as before); seq-to-map-for-destructuring is the
internal &{:keys} helper. Largely exhausts the easy pure-eager tier.
conformance 228/228 x3, full suite green (incl. destructuring).
This commit is contained in:
parent
fec5a10ccf
commit
f0e111563b
3 changed files with 25 additions and 19 deletions
|
|
@ -192,3 +192,24 @@
|
|||
|
||||
;; No ratio type on Jolt, so rationalize is identity.
|
||||
(defn rationalize [x] x)
|
||||
|
||||
;; Eager dedupe of consecutive equal elements (Jolt has no transducer arity yet).
|
||||
(defn dedupe [coll]
|
||||
(let [c (vec coll)]
|
||||
(if (empty? c)
|
||||
[]
|
||||
(loop [prev (first c) xs (rest c) out [(first c)]]
|
||||
(if (seq xs)
|
||||
(let [x (first xs)]
|
||||
(recur x (rest xs) (if (= x prev) out (conj out x))))
|
||||
out)))))
|
||||
|
||||
;; Internal helper for {:keys [...]} destructuring over a seq of k/v pairs:
|
||||
;; builds a map from consecutive pairs, dropping a trailing unpaired element.
|
||||
(defn seq-to-map-for-destructuring [s]
|
||||
(if (sequential? s)
|
||||
(loop [m {} xs (seq s)]
|
||||
(if (and xs (next xs))
|
||||
(recur (assoc m (first xs) (second xs)) (next (next xs)))
|
||||
m))
|
||||
s))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue