-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathohm-collection.lisp
42 lines (32 loc) · 1.48 KB
/
ohm-collection.lisp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
;;; ohm-collection.lisp
(in-package #:cl-ohm)
(defclass ohm-collection ()
((key :reader key
:initarg :key)
(element-type :reader element-type
:initarg :element-type)))
;;;;;;;;;;;;;;;;;;;;;;;;;; OHM-COLLECTION PROTOCOL ;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgeneric add (collection element)
(:documentation "Adds a ELEMENT to the COLLECTION. ELEMENT must be a persistable object.")
(:method :before ((collection ohm-collection) (element ohm-object))
(declare (ignore collection))
(ensure-id element)))
(defgeneric remove (collection element)
(:documentation "Removes ELEMENT from the COLLECTION.")
(:method :before ((collection ohm-collection) (element ohm-object))
(declare (ignore collection))
(ensure-id element)))
(defgeneric replace (collection new-elements)
(:documentation "Replaces the COLLECTION's elements with NEW-ELEMENTS.")
(:method :before ((collection ohm-collection) new-elements)
(declare (ignore collection))
(mapc #'ensure-id new-elements)))
(defgeneric size (collection)
(:documentation "Returns the number of elements in the COLLECTION."))
(defgeneric member (collection element)
(:documentation "Checks if ELEMENT is a member of COLLECTION.")
(:method :before ((collection ohm-collection) (element ohm-object))
(declare (ignore collection))
(ensure-id element)))
(defgeneric elements (collection)
(:documentation "Returns all elements in COLLECTION."))