Skip to content

Instantly share code, notes, and snippets.

@duncanmak
Created October 28, 2010 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duncanmak/652322 to your computer and use it in GitHub Desktop.
Save duncanmak/652322 to your computer and use it in GitHub Desktop.
(defn projections-on-section
"From a map of {key, {:entries {s [sx sy] ...} ...}} and 's', return a map of {key, [sx sy]}"
[all-trails section]
{:pre [(map? all-trails)]
:post [(map? %) (every? key? (keys %)) (every? vpoint? (vals %))]}
(let [trails (filter #(contains? (:entries (val %)) section) all-trails)]
(with-meta
(into {} (map (fn [t]
(let [id (key t), trail (val t)
entries (get (:entries trail) section)]
{id (->vpoint (first entries))}))
trails))
{:section section})))
@duncanmak
Copy link
Author

(defn projections-on-section
"From a map of {key, {:entries {s [sx sy] ...} ...}} and 's', return a map of {key, [sx sy]}"
[all-trails section]
{:pre [(map? all-trails)]
:post [(map? %) (every? key? (keys %)) (every? vpoint? (vals %))]}
(let [trails (filter #(contains? (:entries (val %)) section) all-trails)](with-meta
%28into {}
;; %28map %28fn [t]
;; %28let [id %28key t%29, trail %28val t%29
;; entries %28get %28:entries trail%29 section%29]
;; {id %28->vpoint %28first entries%29%29}%29%29
;; trails%29
%28for [[id trail] trails]
{id %28->vpoint %28first %28get %28:entries trail%29 section%29%29%29}%29
%29
{:section section})))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment