       (for [c (find-header-or-data-cells r)]
         (failsafe-text c)))))
 
+(def ffilter (comp first filter))
 
 (defn some-what 
   "works like some, but returns the value which satisfied the predicate"


(defn index-tables []
  (for [t (find-elements [{:tag :table}])]
    (map vector (range) (index-table-text t))
    )
  )

(defn match? [re x]
  (try

    (catch NullPointerException e false) ))

(defn search-table [t re]
    (ffilter #(match? re (last %)) t))

(defn find-cell-by-coordinate [coords]
  (println "finding cell by coordinate:" coords)
  (let [candidates (ffilter #(get % coords ) @itables)]
    (second (first (remove #(nil? (second %)) candidates)))
    ))

(defn find-cell-by-offset [coords re]
  (println "finding cell by offset:" coords re)
  (let [match  (map #(vector (second %) (search-table (first %) re)) (map vector @itables (range)))
        match (first (remove #(nil? (second %)) match)) ]
    (println "matched:" match)
    (when-let [matchedcoords (get-in match [1 0])]
      (let [newcoords (mapv + coords matchedcoords)]
        (println newcoords)
        (get (nth @itables (first match)) newcoords)))))

;location should be like:
;[:offset [x,y]]
;[x,y]
(defn find-table-cell-by-location [location]
  (println "finding table cell by location" location )
  (case (first location)
    :offset (find-cell-by-offset (first (rest location)) (last location))
    (find-cell-by-coordinate (first location))
    )
  )

(defn dispatch-location [location]  
  (println "dispatching" location)
  (case (first location)
    :table (find-table-cell-by-location (rest location))
    :miss)
    )

