summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNic Ferier <nic@ferrier.me.uk>2012-09-15 21:38:45 +0100
committerNic Ferier <nic@ferrier.me.uk>2012-09-15 21:38:45 +0100
commit316ca3715903414e5c13546b17b7397f1d8a944e (patch)
tree16f65ef45dbc0300a2902a4ece7a35ea490a6b31
parentadaa43e9411e6a6331e640aac683490557221c35 (diff)
kvalist2->alist function
-rw-r--r--kv.el21
1 files changed, 20 insertions, 1 deletions
diff --git a/kv.el b/kv.el
index 54505a9..5e18786 100644
--- a/kv.el
+++ b/kv.el
@@ -125,7 +125,11 @@ Only pairs where the car is a `member' of KEYS will be returned."
collect a))
(defun kvplist->filter-keys (plist &rest keys)
- "Filter the plist to just keys."
+ "Filter the plist to just those matching KEYS.
+
+KEYS must actually be :-less symbols.
+
+`kvalist->filter-keys' is actually used to do this work."
(kvalist->plist
(apply
'kvalist->filter-keys
@@ -136,6 +140,21 @@ Only pairs where the car is a `member' of KEYS will be returned."
(loop for plist in plist2
collect (apply 'kvplist->filter-keys (cons plist keys))))
+(defun kvalist2->filter-keys (alist2 &rest keys)
+ "Return the ALIST2 (a list of alists) filtered to the KEYS."
+ (loop for alist in alist2
+ collect (apply 'kvalist->filter-keys (cons alist keys))))
+
+(defun kvalist2->alist (alist2 car-key cdr-key)
+ "Reduce the ALIST2 (a list of alists) to a single alist.
+
+CAR-KEY is the key of each alist to use as the resulting key and
+CDR-KEY is the key of each alist to user as the resulting cdr."
+ (loop for alist in alist2
+ collect (cons
+ (assoc-default car-key alist)
+ (assoc-default cdr-key alist))))
+
(defun kvcmp (a b)
"Do a comparison of the two values using printable syntax.