From f93432a241e2f5ff32b0cadcaf566e36db6c7ed8 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 30 May 2020 14:09:14 +0100 Subject: [PATCH] #3: Still problems in index-vertices, I think --- src/walkmap/superstructure.clj | 65 +++++++++++++++++++++------------- src/walkmap/utils.clj | 2 ++ 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/walkmap/superstructure.clj b/src/walkmap/superstructure.clj index fec969c..85ac57d 100644 --- a/src/walkmap/superstructure.clj +++ b/src/walkmap/superstructure.clj @@ -63,14 +63,31 @@ 2. `o` is not a map; 3. `o` does not have a value for the key `:walkmap.id/id`." [s o] - (assoc + (u/deep-merge s - :vertex-index - (reduce - u/deep-merge - (map - #(index-vertex s o %) - (vertices o))))) + {:vertex-index + (reduce + u/deep-merge + {} + (map + #(index-vertex s o %) + (:vertices o)))})) + +(defn in-retrieve-map + "Internal to `in-retrieve`, q.v. Handle the case where `x` is a map. + Separated out for debugging/unit testing purposes. Use at your own peril." + [x s] + (let [v (reduce + (fn [m k] + (assoc m k (in-retrieve (x k) s))) + {} + (keys (dissoc x :walkmap.id/id))) + id (:walkmap.id/id x)] + (if id + (assoc + v + :walkmap.id/id + (:walkmap.id/id x))))) (defn in-retrieve "Internal guts of `retrieve`, q.v. `x` can be anything; `s` must be a @@ -84,13 +101,7 @@ (in-retrieve (s x) s) x) ;; if it's a map, for every key which is not `:walkmap.id/id`, recurse. - (map? x) (reduce - (fn [m k] - (if (= k :walkmap.id/id) - k - (assoc m k (in-retrieve (x k) s)))) - {} - (keys x)) + (map? x) (in-retrieve-map x s) (coll? x) (map #(in-retrieve % s) x) :else x)) @@ -140,18 +151,22 @@ 1. `s` is not a map; 2. `o` is not a recognisable walkmap object" ([o] - (store {} o)) + (store o {})) ([o s] -;; (when-not (:walkmap.id/id o) -;; (throw -;; (IllegalArgumentException. -;; (str "Not a walkmap object: no value for `:walkmap.id/id`: " -;; (u/kind-type o))))) -;; (when-not (map? s) -;; (throw -;; (IllegalArgumentException. -;; (str "Superstructure must be a map: " (u/kind-type s))))) + (when-not (:walkmap.id/id o) + (throw + (IllegalArgumentException. + (str "Not a walkmap object: no value for `:walkmap.id/id`: " + (u/kind-type o))))) + (when-not (map? s) + (throw + (IllegalArgumentException. + (str "Superstructure must be a map: " (u/kind-type s))))) (assoc (u/deep-merge s (in-store-find-objects o)) (:walkmap.id/id o) - (in-store-replace-with-keys o)))) + (in-store-replace-with-keys o) + :vertex-index + (u/deep-merge + (index-vertices s o) + (:vertex-index s))))) diff --git a/src/walkmap/utils.clj b/src/walkmap/utils.clj index 643f00f..8fa7197 100644 --- a/src/walkmap/utils.clj +++ b/src/walkmap/utils.clj @@ -5,6 +5,8 @@ (defn deep-merge "Recursively merges maps. If vals are not maps, the last value wins." ;; TODO: not my implementation, not sure I entirely trust it. + ;; TODO TODO: if we are to successfully merge walkmap objects, we must + ;; return, on each object, the union of its tags if any. [& vals] (if (every? map? vals) (apply merge-with deep-merge vals)