emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash e720428 010/439: Extract basic iteration form into


From: Phillip Lord
Subject: [elpa] externals/dash e720428 010/439: Extract basic iteration form into macro.
Date: Tue, 04 Aug 2015 20:25:50 +0000

branch: externals/dash
commit e7204280cec92deba0b52ad9e392c6bd7755c485
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Extract basic iteration form into macro.
    
     - needs some love
---
 bang.el |   32 +++++++++++++++-----------------
 1 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/bang.el b/bang.el
index 8859802..1436a9c 100644
--- a/bang.el
+++ b/bang.el
@@ -46,37 +46,35 @@ It should only be set using dynamic scope with a let, like:
 (defun !mapcat (fn list)
   (!concat (!map fn list)))
 
+(defmacro !--iterate-with-result (&rest forms)
+  `(let (result)
+     (while list
+       (let ((it (car list))) ,@forms)
+       (setq list (cdr list)))
+     (nreverse result)))
+
 (defun !uniq (list)
   "Return a new list with all duplicates removed.
 The test for equality is done with `equal',
 or with `!compare-fn' if that's non-nil."
-  (let (result)
-    (while list
-      (add-to-list 'result (car list) nil !compare-fn)
-      (setq list (cdr list)))
-    (nreverse result)))
+  (!--iterate-with-result
+   (add-to-list 'result it nil !compare-fn)))
 
 (defun !intersection (list list2)
   "Return a new list containing only the elements that are members of both 
LIST and LIST2.
 The test for equality is done with `equal',
 or with `!compare-fn' if that's non-nil."
-  (let (result)
-    (while list
-      (when (!contains-p list2 (car list))
-        (setq result (cons (car list) result)))
-      (setq list (cdr list)))
-    (nreverse result)))
+  (!--iterate-with-result
+   (when (!contains-p list2 it)
+     (setq result (cons it result)))))
 
 (defun !difference (list list2)
   "Return a new list with only the members of LIST that are not in LIST2.
 The test for equality is done with `equal',
 or with `!compare-fn' if that's non-nil."
-  (let (result)
-    (while list
-      (unless (!contains-p list2 (car list))
-        (setq result (cons (car list) result)))
-      (setq list (cdr list)))
-    (nreverse result)))
+  (!--iterate-with-result
+   (unless (!contains-p list2 it)
+     (setq result (cons it result)))))
 
 (defun !contains-p (list element)
   "Return whether LIST contains ELEMENT.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]