Restore 20-coll.clj from known-good commit 64b1c60
File was corrupted by stash-merge conflict markers. Restored clean version from the commit where 22/22 harness was verified.
This commit is contained in:
parent
9a82411e34
commit
0782bf3e48
1 changed files with 12 additions and 21 deletions
|
|
@ -210,38 +210,29 @@
|
||||||
|
|
||||||
;; trampoline: repeatedly calls f with args until a non-function result.
|
;; trampoline: repeatedly calls f with args until a non-function result.
|
||||||
(defn trampoline
|
(defn trampoline
|
||||||
([f]
|
([f] (trampoline f (f)))
|
||||||
(let [ret (f)]
|
|
||||||
(if (ifn? ret)
|
|
||||||
(recur ret)
|
|
||||||
ret)))
|
|
||||||
([f & args]
|
([f & args]
|
||||||
(let [ret (apply f args)]
|
(let [ret (apply f args)]
|
||||||
(if (ifn? ret)
|
(if (fn? ret)
|
||||||
(recur ret)
|
(recur ret)
|
||||||
ret))))
|
ret))))
|
||||||
|
|
||||||
;; rand-int: random integer in [0, n). Uses Janet math/random.
|
;; rand-int: random integer in [0, n). Uses Janet math/random.
|
||||||
# rand-int stays native in core.janet (Janet math/floor + math/random)
|
(defn rand-int [n] (math/floor (* (math/random) n)))
|
||||||
|
|
||||||
;; Eager dedupe of consecutive equal elements (Jolt has no transducer arity yet).
|
;; Eager dedupe of consecutive equal elements (Jolt has no transducer arity yet).
|
||||||
(defn dedupe
|
(defn dedupe [coll]
|
||||||
"Returns a lazy seq removing consecutive duplicates in coll."
|
|
||||||
[coll]
|
|
||||||
(let [step (fn step [s prev]
|
(let [step (fn step [s prev]
|
||||||
(make-lazy-seq
|
(lazy-seq
|
||||||
(fn* []
|
|
||||||
(let [s (seq s)]
|
(let [s (seq s)]
|
||||||
(if s
|
(when s
|
||||||
(let [x (first s)]
|
(let [x (first s)]
|
||||||
(if (= x prev)
|
(if (= x prev)
|
||||||
(coll->cells (step (rest s) prev))
|
(step (rest s) prev)
|
||||||
(coll->cells (cons x (step (rest s) x)))))
|
(cons x (step (rest s) x))))))))]
|
||||||
nil)))))]
|
|
||||||
(let [s (seq coll)]
|
(let [s (seq coll)]
|
||||||
(if s
|
(if s
|
||||||
(make-lazy-seq
|
(cons (first s) (step (rest s) (first s)))
|
||||||
(fn* [] (coll->cells (cons (first s) (step (rest s) (first s))))))
|
|
||||||
()))))
|
()))))
|
||||||
|
|
||||||
;; Internal helper for {:keys [...]} destructuring over a seq of k/v pairs:
|
;; Internal helper for {:keys [...]} destructuring over a seq of k/v pairs:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue