|
1 | 1 | (ns datascript.built-ins |
2 | 2 | (:require |
3 | | - [clojure.string :as str] |
4 | | - [datascript.db :as db] |
5 | | - [datascript.impl.entity :as de] |
6 | | - [datascript.util :as util])) |
| 3 | + [clojure.string :as str] |
| 4 | + [datascript.db :as db] |
| 5 | + [datascript.impl.entity :as de] |
| 6 | + [datascript.util :as util])) |
7 | 7 |
|
8 | 8 | (defn- -differ? [& xs] |
9 | 9 | (let [l (count xs)] |
|
20 | 20 | (defn- -get-some |
21 | 21 | [db e & as] |
22 | 22 | (reduce |
23 | | - (fn [_ a] |
24 | | - (when-some [datom (first (db/-search db [(db/entid db e) a]))] |
25 | | - (reduced [(:a datom) (:v datom)]))) |
26 | | - nil |
27 | | - as)) |
| 23 | + (fn [_ a] |
| 24 | + (when-some [datom (first (db/-search db [(db/entid db e) a]))] |
| 25 | + (reduced [(:a datom) (:v datom)]))) |
| 26 | + nil |
| 27 | + as)) |
28 | 28 |
|
29 | 29 | (defn- -missing? |
30 | 30 | [db e a] |
|
80 | 80 |
|
81 | 81 | (def query-fns |
82 | 82 | {'= =, '== ==, 'not= not=, '!= not=, |
83 | | - '< less, '> greater, '<= less-equal, '>= greater-equal, |
84 | | - '+ +, '- -, '* *, '/ /, |
85 | | - 'quot quot, 'rem rem, 'mod mod, 'inc inc, 'dec dec, 'max max, 'min min, |
86 | | - 'zero? zero?, 'pos? pos?, 'neg? neg?, 'even? even?, 'odd? odd?, 'compare compare, |
87 | | - 'rand rand, 'rand-int rand-int, |
88 | | - 'true? true?, 'false? false?, 'nil? nil?, 'some? some?, 'not not, 'and and-fn, 'or or-fn, |
89 | | - 'complement complement, 'identical? identical?, |
90 | | - 'identity identity, 'keyword keyword, 'meta meta, 'name name, 'namespace namespace, 'type type, |
91 | | - 'vector vector, 'list list, 'set set, 'hash-map hash-map, 'array-map array-map, |
92 | | - 'count count, 'range range, 'not-empty not-empty, 'empty? empty?, 'contains? contains?, |
93 | | - 'str str, 'subs, subs, 'get get, |
94 | | - 'pr-str pr-str, 'print-str print-str, 'println-str println-str, 'prn-str prn-str, |
95 | | - 're-find re-find, 're-matches re-matches, 're-seq re-seq, 're-pattern re-pattern, |
96 | | - '-differ? -differ?, 'get-else -get-else, 'get-some -get-some, 'missing? -missing?, 'ground identity, |
97 | | - 'clojure.string/blank? str/blank?, 'clojure.string/includes? str/includes?, |
98 | | - 'clojure.string/starts-with? str/starts-with?, 'clojure.string/ends-with? str/ends-with? |
99 | | - 'tuple vector, 'untuple identity}) |
| 83 | + '< less, '> greater, '<= less-equal, '>= greater-equal, |
| 84 | + '+ +, '- -, '* *, '/ /, |
| 85 | + 'quot quot, 'rem rem, 'mod mod, 'inc inc, 'dec dec, 'max max, 'min min, |
| 86 | + 'zero? zero?, 'pos? pos?, 'neg? neg?, 'even? even?, 'odd? odd?, 'compare compare, |
| 87 | + 'rand rand, 'rand-int rand-int, |
| 88 | + 'true? true?, 'false? false?, 'nil? nil?, 'some? some?, 'not not, 'and and-fn, 'or or-fn, |
| 89 | + 'complement complement, 'identical? identical?, |
| 90 | + 'identity identity, 'keyword keyword, 'meta meta, 'name name, 'namespace namespace, 'type type, |
| 91 | + 'vector vector, 'list list, 'set set, 'hash-map hash-map, 'array-map array-map, |
| 92 | + 'count count, 'range range, 'not-empty not-empty, 'empty? empty?, 'contains? contains?, |
| 93 | + 'str str, 'subs, subs, 'get get, |
| 94 | + 'pr-str pr-str, 'print-str print-str, 'println-str println-str, 'prn-str prn-str, |
| 95 | + 're-find re-find, 're-matches re-matches, 're-seq re-seq, 're-pattern re-pattern, |
| 96 | + '-differ? -differ?, 'get-else -get-else, 'get-some -get-some, 'missing? -missing?, 'ground identity, |
| 97 | + 'clojure.string/blank? str/blank?, 'clojure.string/includes? str/includes?, |
| 98 | + 'clojure.string/starts-with? str/starts-with?, 'clojure.string/ends-with? str/ends-with? |
| 99 | + 'tuple vector, 'untuple identity}) |
100 | 100 |
|
101 | 101 | ;; Aggregates |
102 | 102 |
|
|
113 | 113 | (cond-> (nth terms med) |
114 | 114 | (even? size) |
115 | 115 | (-> (+ (nth terms (dec med))) |
116 | | - (/ 2))))) |
| 116 | + (/ 2))))) |
117 | 117 |
|
118 | 118 | (defn- aggregate-variance [coll] |
119 | 119 | (let [mean (aggregate-avg coll) |
|
138 | 138 | (reduce (fn [acc x] |
139 | 139 | (cond |
140 | 140 | (< (count acc) n) |
141 | | - (sort compare (conj acc x)) |
| 141 | + (sort compare (conj acc x)) |
142 | 142 | (neg? (compare x (last acc))) |
143 | | - (sort compare (conj (butlast acc) x)) |
| 143 | + (sort compare (conj (butlast acc) x)) |
144 | 144 | :else acc)) |
145 | | - [] coll)))) |
| 145 | + [] coll)))) |
146 | 146 |
|
147 | 147 | (defn- aggregate-max |
148 | 148 | ([coll] |
|
152 | 152 | x acc)) |
153 | 153 | (first coll) (next coll))) |
154 | 154 | ([n coll] |
155 | | - (vec |
156 | | - (reduce (fn [acc x] |
157 | | - (cond |
158 | | - (< (count acc) n) |
159 | | - (sort compare (conj acc x)) |
160 | | - (pos? (compare x (first acc))) |
161 | | - (sort compare (conj (next acc) x)) |
162 | | - :else acc)) |
163 | | - [] coll)))) |
| 155 | + (vec |
| 156 | + (reduce (fn [acc x] |
| 157 | + (cond |
| 158 | + (< (count acc) n) |
| 159 | + (sort compare (conj acc x)) |
| 160 | + (pos? (compare x (first acc))) |
| 161 | + (sort compare (conj (next acc) x)) |
| 162 | + :else acc)) |
| 163 | + [] coll)))) |
164 | 164 |
|
165 | 165 | (defn- aggregate-rand |
166 | 166 | ([coll] (rand-nth coll)) |
|
0 commit comments