Permalink
Browse files

kvalist2->alist function

  • Loading branch information...
1 parent adaa43e commit 316ca3715903414e5c13546b17b7397f1d8a944e @nicferrier committed Sep 15, 2012
Showing with 20 additions and 1 deletion.
  1. +20 −1 kv.el
View
21 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.

0 comments on commit 316ca37

Please sign in to comment.