Permalink
Browse files

Added mapping abstraction for structural transforms

* kv.el: Added the function kv-map-bind and the alias map-bind, see
  esxml.el for examples.
  • Loading branch information...
1 parent e485201 commit e8cbf5bac1eddb04492ab8f96e3f29c8033078ba @tali713 tali713 committed Sep 19, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 kv.el
View
@@ -219,6 +219,22 @@ FUNC is some sort of `assoc' like function."
(defalias 'dotassoc 'kvdotassoc)
(defalias 'dotassq 'kvdotassq)
+(defmacro kv-map-bind (args sexp seq)
+ "A hybrid of `destructuring-bind' and `mapcar'
+ARGS shall be of the form used with `destructuring-bind'
+
+Unlike most other mapping forms this is a macro intended to be
+used for structural transformations, so the expected usage will
+be that ARGS describes the structure of the items in SEQ, and
+SEXP will describe the structure desired."
+ (declare (indent 2))
+ (let ((entry (gensym)))
+ `(mapcar (lambda (,entry)
+ (destructuring-bind ,args ,entry ,sexp))
+ ,seq)))
+
+(defalias 'map-bind 'kv-map-bind)
+
(provide 'kv)
(provide 'dotassoc)

0 comments on commit e8cbf5b

Please sign in to comment.