Last active
March 18, 2018 16:29
-
-
Save hmaurer/795d5f8ae49b8df51fe275c745401041 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn compose-cycles [cycle-a cycle-b] | |
(let [inv-cycle-a (clojure.set/map-invert cycle-a)] | |
(reduce-kv | |
(fn [acc k v] | |
(cond | |
(contains? inv-cycle-a k) (assoc acc (get inv-cycle-a k) v) | |
(contains? cycle-a k) acc | |
:else (assoc acc k v))) | |
cycle-a | |
cycle-b))) | |
(defn compose-cycles [cycle-a cycle-b] | |
(merge | |
cycle-b | |
(into {} | |
(for [[k v] cycle-a] | |
[k (get cycle-b v v)])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment