diff options
author | Nic Ferier <nic@ferrier.me.uk> | 2013-04-07 14:18:15 +0100 |
---|---|---|
committer | Nic Ferier <nic@ferrier.me.uk> | 2013-04-07 14:18:15 +0100 |
commit | b227839532b7858ad5b70733dcfadf0653ce2e7f (patch) | |
tree | 79afbafd911fab3deafcd67ef2d16d060e22cd8a | |
parent | 688ba7a0e82068598c3f5773c58515a6bb01380f (diff) |
add transform option to kvalist-keys->symbols
-rw-r--r-- | kv-tests.el | 8 | ||||
-rw-r--r-- | kv.el | 16 |
2 files changed, 19 insertions, 5 deletions
diff --git a/kv-tests.el b/kv-tests.el index adbaa49..ed97035 100644 --- a/kv-tests.el +++ b/kv-tests.el @@ -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 @@ -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." |