                   lastki))]
       (if-not (nil? idx)
         (get m idx)
-        not-found)))
+        (or not-found fallback-val))))
 
 
   clojure.lang.IFn

                                          (fn [lastki ki] ki)]
                           :find-ceiling [(fn [lastki ki] ki)
                                          (fn [lastki ki] lastki)])]
    (->RangeMap kind (apply sorted-map kvs) leftfn rightfn)))

(defn range-map-ceiling [& kvs]
  (apply range-map :find-ceiling kvs))

(defn range-map-floor [& kvs]
  (apply range-map :find-floor kvs))

(ns sample.rangemap)


(deftype RangeMap [kind ^clojure.lang.IPersistentMap m leftfn rightfn fallback-val]

  clojure.lang.MapEquivalence

  clojure.lang.IPersistentMap

  (assoc [this k v]
    (RangeMap. kind (.assoc m k v) leftfn rightfn fallback-val))

  (assocEx [this k v]
    (RangeMap. kind (.assocEx m k v) leftfn rightfn fallback-val))

  (without [this k]
    (RangeMap. kind (.without m k) leftfn rightfn fallback-val))


  clojure.lang.ILookup
