001  (ns the-great-game.utils)
002  
003  (defn cyclic?
004    "True if two or more elements of `route` are identical"
005    [route]
006    (not= (count route)(count (set route))))
007  
008  (defn deep-merge
009    "Recursively merges maps. Stolen from
010    https://dnaeon.github.io/recursively-merging-maps-in-clojure/"
011    [& maps]
012    (letfn [(m [& xs]
013               (if (some #(and (map? %) (not (record? %))) xs)
014                 (apply merge-with m xs)
015                 (last xs)))]
016      (reduce m maps)))
017  
018  (defn make-target-filter
019    "Construct a filter which, when applied to a list of maps,
020    will pass those which match these `targets`, where each target
021    is a tuple [key value]."
022    ;; TODO: this would probably be more elegant as a macro
023    [targets]
024    (eval
025      (list
026        'fn
027        (vector 'm)
028        (cons
029          'and
030          (map
031            #(list
032               '=
033               (list (first %) 'm)
034               (nth % 1))
035            targets)))))