Skip to content

Commit

Permalink
Rewrite cl-loop as seq-mapcat, seq-mapcat, seq-map
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Jul 12, 2022
1 parent 28a1057 commit c078368
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 9 additions & 8 deletions clj-refactor.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
16 changes: 8 additions & 8 deletions tests/unit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c078368

Please sign in to comment.