File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ (ns ^{:doc " Some common utilities for storage functions"
2+ :author " Paula Gearon" }
3+ naga.storage.store-util
4+ (:require [schema.core :as s]
5+ [naga.schema.structs :as st :refer [EPVPattern Value]]
6+ [naga.store :as store]))
7+
8+ (s/defn project-row :- [s/Any]
9+ " Creates a new EPVPattern from an existing one, based on existing bindings.
10+ Uses the mapping to copy from columns in 'row' to overwrite variables in 'pattern'.
11+ 'pattern' must be a vector.
12+ The index mappings have already been found and are in the 'mapping' argument"
13+ [storage
14+ patterns :- [EPVPattern]
15+ mapping :- {s/Num s/Num}
16+ row :- [Value]]
17+ (let [wide-pattern (vec (apply concat patterns))
18+ get-node (memoize (fn [n] (store/new-node storage)))
19+ update-pattern (fn [p [t f]]
20+ (let [v (if (< f 0 ) (get-node f) (nth row f))]
21+ (assoc p t v)))]
22+ (partition 3
23+ (reduce update-pattern wide-pattern mapping))))
You can’t perform that action at this time.
0 commit comments