From c07836894f6eb83b224fcbc3651c6bc855b66972 Mon Sep 17 00:00:00 2001 From: Charles Comstock Date: Mon, 11 Jul 2022 19:26:36 -0500 Subject: [PATCH] Rewrite cl-loop as seq-mapcat, seq-mapcat, seq-map --- clj-refactor.el | 17 +++++++++-------- tests/unit-test.el | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/clj-refactor.el b/clj-refactor.el index ebf41ecd..f3216a4b 100644 --- a/clj-refactor.el +++ b/clj-refactor.el @@ -1970,14 +1970,15 @@ following this convention: https://stuartsierra.com/2015/05/10/clojure-namespace "Calculate a list of alias, namespace, lang-contexts from middleware." (when-let (aliases (cljr--call-middleware-for-namespace-aliases)) (let ((alias-list ; list of all alias, require, lang-context - (cl-loop for lang-context being the hash-keys of aliases - using (hash-values alias-vals) - append - (cl-loop for alias-name being the hash-keys of alias-vals - using (hash-values alias-requires) - append - (cl-loop for alias-require being the elements of alias-requires - collect (list alias-name alias-require lang-context)))))) + (seq-mapcat + (lambda (lang-context) + (seq-mapcat + (lambda (alias) + (seq-map (lambda (namespace) + (list alias namespace lang-context)) + (gethash alias (gethash lang-context aliases)))) + (hash-table-keys (gethash lang-context aliases)))) + (hash-table-keys aliases)))) ;; Collapse from alias-list into a unique list of ;; alias,require,lang-context(s). (seq-map (lambda (elt) (append (car elt) (cdr elt))) diff --git a/tests/unit-test.el b/tests/unit-test.el index d796031e..f4b10893 100644 --- a/tests/unit-test.el +++ b/tests/unit-test.el @@ -104,18 +104,18 @@ (describe "cljr--list-namespace-aliases" (it "reduces to a unique list from middleware" (spy-on 'cljr--call-middleware-for-namespace-aliases - :and-return-value - (parseedn-read-str - "{:clj {t (clojure.test) set (clojure.set) sut (alpha shared)} + :and-return-value + (parseedn-read-str + "{:clj {t (clojure.test) set (clojure.set) sut (alpha shared)} :cljs {t (cljs.test) set (clojure.set) sut (beta shared)}}")) (expect (cljr--list-namespace-aliases) :to-equal - '((t clojure.test (:clj)) - (sut alpha (:clj)) + '((sut beta (:cljs)) (t cljs.test (:cljs)) - (set clojure.set (:clj :cljs)) - (sut beta (:cljs)) - (sut shared (:clj :cljs)))))) + (sut alpha (:clj)) + (sut shared (:cljs :clj)) + (set clojure.set (:cljs :clj)) + (t clojure.test (:clj)))))) (describe "cljr--magic-require-candidates" (it "generates candidates from middleware that match"