Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created March 18, 2016 04:17
Show Gist options
  • Select an option

  • Save alandipert/1700e9e6b8187a75158b to your computer and use it in GitHub Desktop.

Select an option

Save alandipert/1700e9e6b8187a75158b to your computer and use it in GitHub Desktop.
(def-map-type MapLayer [hm dissoced m mta]
(get [_ k default-value]
(let [v (get m k ::none)]
(if (= v ::none)
(if (contains? dissoced k)
default-value
(get hm k default-value))
v)))
(assoc [_ k v]
(MapLayer. hm (disj dissoced k) (assoc m k v) mta))
(dissoc [_ k]
(MapLayer. hm (conj dissoced k) (dissoc m k) mta))
(keys [_]
(vec (set/union (set/difference (set (keys hm)) dissoced) (set (keys m)))))
(meta [_] mta)
(with-meta [_ mta]
(MapLayer. hm dissoced m mta)))
(defn map-layer
"Civilizes java.util.Maps"
[java-hashmap]
(MapLayer. java-hashmap #{} {} {}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment