 ;;--------------------------------------------------------------------------------
 ;; this layer encapsulates access to lhs index
 
+(defn- lhses-get [lhs-indeces i key]
+  (key (nth lhs-indeces (dec i))))
+
 (defn- lhs-assoc [old-indeces keys lhs]
   "associate a new lhs with existing index"
   (let [[old-lhs-index & rhs-indeces] old-indeces

;; TODO: return a pair - first is notification fn, second is new-indeces - use swap*! to apply

(defn- rhs-upsert [old-indeces i lhs-key rhs-ks v join-fn joined-model]
  (let [new-indeces (rhs-assoc old-indeces i lhs-key v)
	lhs-indeces (first old-indeces)
	lhs-index (nth lhs-indeces (dec i))
	lhses ((lhs-key v) lhs-index)
	rhs-indeces (rest new-indeces)
	joins (mapcat (fn [lhs] (derive-joins lhs rhs-indeces rhs-ks join-fn)) lhses)
	]

;;--------------------------------------------------------------------------------
;; this layer encapsulates access to rhs indeces

(defn- rhs-assoc [old-indeces i value rhs]
  (let [old-index (nth old-indeces i)
	old-rhses (or (value old-index) [])
	new-rhses (conj old-rhses rhs)
	new-index (assoc old-index value new-rhses)
	new-indeces (assoc old-indeces i new-index)]
