-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb-functions.lisp
More file actions
30 lines (25 loc) · 965 Bytes
/
db-functions.lisp
File metadata and controls
30 lines (25 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(in-package #:xdb2)
(defgeneric sum (collection &key function &allow-other-keys)
(:documentation "Applies the function to all the docs in the collection and returns the sum of
the return values."))
(defmethod sum ((collection collection) &key function element)
(let* ((sum 0)
(function (or function
(lambda (doc)
(incf sum (get-val doc element))))))
(map-docs nil
function
collection)
sum))
(defgeneric max-val (collection &key function element))
(defmethod max-val ((collection collection) &key function element)
(let* ((max 0)
(function (or function
(lambda (doc)
(if (get-val doc element)
(if (> (get-val doc element) max)
(setf max (get-val doc element))))))))
(map-docs nil
function
collection)
max))