Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more new functions

  • Loading branch information...
commit b4c0549913c8ca643a90eb9b879d185cadd0b379 1 parent 4210b1f
Nic Ferrier authored
Showing with 44 additions and 1 deletion.
  1. +44 −1 kv.el
45 kv.el
View
@@ -4,7 +4,7 @@
;; Author: Nic Ferrier <nferrier@ferrier.me.uk>
;; Keywords: lisp
-;; Version: 0.0.4
+;; Version: 0.0.5
;; Maintainer: Nic Ferrier <nferrier@ferrier.me.uk>
;; Created: 7th September 2012
@@ -71,6 +71,34 @@ HASH-TABLE-ARGS are passed to the hash-table creation."
(car pair)))))
(cdr pair))))
+(defun kvplist->alist (plist)
+ "Convert PLIST to an alist.
+
+The keys are expected to be :prefixed and the colons are removed.
+The keys in the resulting alist are symbols."
+ (labels
+ ((plist->alist-cons (a b lst)
+ (let ((key (intern (substring (symbol-name a) 1))))
+ (if (car-safe lst)
+ (cons
+ (cons key b)
+ (plist->alist-cons
+ (car lst)
+ (cadr lst)
+ (cddr lst)))
+ ;; Else
+ (cons (cons key b) nil)))))
+ (plist->alist-cons
+ (car plist)
+ (cadr plist)
+ (cddr plist))))
+
+(defun kvalist2->plist (alist2)
+ "Convert a list of alists too a list of plists."
+ (loop for alist in alist2
+ append
+ (list (kvalist->plist alist))))
+
(defun kvalist->keys (alist)
"Get just the keys from the alist."
(mapcar (lambda (pair) (car pair)) alist))
@@ -95,6 +123,21 @@ Only pairs where the car is a `member' of KEYS will be returned."
if (member (car a) keys)
collect a))
+(defun kvplist->filter-keys (plist &rest keys)
+ "Return the PLIST filtered to the KEYS list.
+
+Only plist parts where the car is a `member' of KEYS will be
+returned."
+ (kvalist->plist
+ (loop for a in (kvplist-> plist)
+ if (member (car a) keys)
+ collect a)))
+
+(defun kvcmp (a b)
+ "Do a comparison of the two values using printable syntax."
+ (string-lessp (format "%S" a)
+ (format "%S" b)))
+
(defun kvdotassoc-fn (expr table func)
"Use the dotted EXPR to access deeply nested data in TABLE.
Please sign in to comment.
Something went wrong with that request. Please try again.