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

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

[elpa] externals/dash 4201ecd 017/439: Out with remove-if, in with !reje


From: Phillip Lord
Subject: [elpa] externals/dash 4201ecd 017/439: Out with remove-if, in with !reject
Date: Tue, 04 Aug 2015 20:25:55 +0000

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

    Out with remove-if, in with !reject
---
 bang.el  |   13 ++++++++++---
 tests.el |   19 +++++++++++++------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/bang.el b/bang.el
index ed5c430..42932ff 100644
--- a/bang.el
+++ b/bang.el
@@ -27,12 +27,17 @@
 
 (eval-when-compile (require 'cl))
 
+(defun !--call-with-it (form-or-fn)
+  (if (functionp form-or-fn)
+      (list form-or-fn 'it)
+    form-or-fn))
+
 (defmacro !filter (form-or-fn list)
   `(let ((!--list ,list)
          (!--result '()))
      (while !--list
        (let ((it (car !--list)))
-         (when ,(if (functionp form-or-fn) (list form-or-fn 'it) (list 'progn 
form-or-fn))
+         (when ,(!--call-with-it form-or-fn)
            (setq !--result (cons it !--result))))
        (setq !--list (cdr !--list)))
      (nreverse !--result)))
@@ -48,7 +53,7 @@
      (while !--list
        (let ((it (car !--list))
              (acc !--acc))
-         (setq !--acc ,(if (functionp form-or-fn) (list form-or-fn 'acc 'it) 
(list 'progn form-or-fn)))
+         (setq !--acc ,(if (functionp form-or-fn) (list form-or-fn 'acc 'it) 
form-or-fn))
          (setq !--list (cdr !--list))))
      !--acc))
 
@@ -63,7 +68,9 @@
   (apply 'append (append lists '(nil))))
 
 (defalias '!select '!filter)
-(defalias '!reject 'remove-if)
+
+(defmacro !reject (form-or-fn list)
+  `(!filter (not ,(!--call-with-it form-or-fn)) ,list))
 
 (defalias '!partial 'apply-partially)
 
diff --git a/tests.el b/tests.el
index a7bc88f..5a72531 100644
--- a/tests.el
+++ b/tests.el
@@ -4,12 +4,6 @@
 (defun even? (num) (= 0 (% num 2)))
 (defun square (num) (* num num))
 
-(ert-deftest filter ()
-  "`!filter' returns a new list of only those elements where the predicate was 
non-nil."
-  (should (equal (!filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) '(2 4)))
-  (should (equal (!filter (= 0 (% it 2)) '(1 2 3 4)) '(2 4)))
-  (should (equal (!filter even? '(1 2 3 4)) '(2 4))))
-
 (ert-deftest map ()
   "`!map' returns a new list with the results of calling the function on each 
element."
   (should (equal (!map (lambda (num) (* num num)) '(1 2 3 4)) '(1 4 9 16)))
@@ -29,6 +23,19 @@
   (should (equal (!reduce (format "%s-%s" acc it) '(1 2 3)) "1-2-3"))
   (should (equal (!reduce (format "%s-%s" acc it) '()) "nil-nil")))
 
+(ert-deftest filter ()
+  "`!filter' returns a new list of only those elements where the predicate was 
non-nil."
+  (should (equal (!filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) '(2 4)))
+  (should (equal (!filter (= 0 (% it 2)) '(1 2 3 4)) '(2 4)))
+  (should (equal (!filter even? '(1 2 3 4)) '(2 4)))
+  (should (equal (!select even? '(1 2 3 4)) '(2 4))))
+
+(ert-deftest reject ()
+  "`!reject' returns a new list of only those elements where the predicate was 
nil."
+  (should (equal (!reject (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) '(1 3)))
+  (should (equal (!reject (= 0 (% it 2)) '(1 2 3 4)) '(1 3)))
+  (should (equal (!reject even? '(1 2 3 4)) '(1 3))))
+
 (ert-deftest concat ()
   "`!concat' returns the concatenation of the elements in the supplied lists"
   (should (equal (!concat) nil))



reply via email to

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