Permalink
Browse files

add transform option to kvalist-keys->symbols

  • Loading branch information...
1 parent 688ba7a commit b227839532b7858ad5b70733dcfadf0653ce2e7f @nicferrier committed Apr 7, 2013
Showing with 19 additions and 5 deletions.
  1. +7 −1 kv-tests.el
  2. +12 −4 kv.el
View
@@ -63,7 +63,13 @@
(equal
'((a . 10)(\10 . 20)(\(a\ b\ c\) . 30))
(kvalist-keys->symbols
- '(("a" . 10)(10 . 20)((a b c) . 30))))))
+ '(("a" . 10)(10 . 20)((a b c) . 30)))))
+ (should
+ (equal
+ '((a . 10)(\10 . 20)(\(a\ b\ c\) . 30))
+ (kvalist-keys->symbols
+ '(("A" . 10)(10 . 20)((a b c) . 30))
+ :first-fn 'downcase))))
(ert-deftest kvassoc= ()
(should
View
16 kv.el
@@ -4,7 +4,7 @@
;; Author: Nic Ferrier <nferrier@ferrier.me.uk>
;; Keywords: lisp
-;; Version: 0.0.14
+;; Version: 0.0.15
;; Maintainer: Nic Ferrier <nferrier@ferrier.me.uk>
;; Created: 7th September 2012
@@ -270,9 +270,17 @@ cons cells."
(cdr pair)))
alist))
-(defun kvalist-keys->symbols (alist)
- "Convert the keys of ALIST into symbols."
- (kvalist-keys->* alist (lambda (key) (intern (format "%s" key)))))
+(defun* kvalist-keys->symbols (alist &key (first-fn 'identity))
+ "Convert the keys of ALIST into symbols.
+
+If key parameter FIRST-FN is present it should be a function
+which will be used to first transform the string key. A popular
+choice might be `downcase' for example, to cause all symbol keys
+to be lower-case."
+ (kvalist-keys->*
+ alist
+ (lambda (key)
+ (intern (funcall first-fn (format "%s" key))))))
(defun kvalist2-filter (alist2 fn)
"Filter the list of alists with FN."

0 comments on commit b227839

Please sign in to comment.