Skip to content

Instantly share code, notes, and snippets.

@hmaurer
Last active March 18, 2018 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmaurer/795d5f8ae49b8df51fe275c745401041 to your computer and use it in GitHub Desktop.
Save hmaurer/795d5f8ae49b8df51fe275c745401041 to your computer and use it in GitHub Desktop.
(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