[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))
- [elpa] externals/dash 93957f0 006/439: Add travis status icon to README, (continued)
- [elpa] externals/dash 93957f0 006/439: Add travis status icon to README, Phillip Lord, 2015/08/04
- [elpa] externals/dash ad44aee 009/439: Add more tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash 065f76b 005/439: Use ert.el to run on Emacs 23 as well., Phillip Lord, 2015/08/04
- [elpa] externals/dash e720428 010/439: Extract basic iteration form into macro., Phillip Lord, 2015/08/04
- [elpa] externals/dash c229ba8 011/439: Rewrite to anaphoric filter function., Phillip Lord, 2015/08/04
- [elpa] externals/dash d870282 013/439: Add some tests, and fix the bugs they uncovered., Phillip Lord, 2015/08/04
- [elpa] externals/dash 3e0ef58 012/439: !filter can now take either a function or form (anaphoric), Phillip Lord, 2015/08/04
- [elpa] externals/dash b24d056 014/439: !map macro, Phillip Lord, 2015/08/04
- [elpa] externals/dash ed2e447 015/439: !reduce macro, Phillip Lord, 2015/08/04
- [elpa] externals/dash f9471e4 016/439: !concat done - one less 'cl dependency, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4201ecd 017/439: Out with remove-if, in with !reject,
Phillip Lord <=
- [elpa] externals/dash f5b16e3 018/439: Make !partial have the same quote-less API as the rest of bang., Phillip Lord, 2015/08/04
- [elpa] externals/dash a02b6c1 021/439: Add note about no 'cl required., Phillip Lord, 2015/08/04
- [elpa] externals/dash 07de30e 019/439: !mapcat macro, and with that: goodbye 'cl!, Phillip Lord, 2015/08/04
- [elpa] externals/dash 52815c5 020/439: Add documentation, Phillip Lord, 2015/08/04
- [elpa] externals/dash 73204ca 022/439: Change !contains-p to !contains? to match clojure api., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6c39876 003/439: Set up test framework with one basic test, Phillip Lord, 2015/08/04
- [elpa] externals/dash c0f2c8f 026/439: Test that it works with lexical binding., Phillip Lord, 2015/08/04
- [elpa] externals/dash 754dd0d 024/439: Create stand-alone anaphoric macros, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9e74cc0 027/439: Remove dead code., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8eab3d1 028/439: Slight improvements to map., Phillip Lord, 2015/08/04