[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 9312469 053/439: !keep
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 9312469 053/439: !keep |
Date: |
Tue, 04 Aug 2015 20:26:18 +0000 |
branch: externals/dash
commit 9312469d1e311c5974e211e355f8790670ac371b
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
!keep
Returns a new list of the non-nil results of applying FN to the items in
LIST.
---
README.md | 11 +++++++++++
bang.el | 16 ++++++++++++++++
examples.el | 5 +++++
3 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 448c548..2daa608 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,7 @@ This is so much a work in progress that you should definitely
not be using it ye
* [!reduce](#reduce-fn-list) `(fn list)`
* [!filter](#filter-fn-list) `(fn list)`
* [!remove](#remove-fn-list) `(fn list)`
+* [!keep](#keep-fn-list) `(fn list)`
* [!concat](#concat-rest-lists) `(&rest lists)`
* [!mapcat](#mapcat-fn-list) `(fn list)`
* [!partial](#partial-fn-rest-args) `(fn &rest args)`
@@ -113,6 +114,16 @@ Returns a new list of the items in `list` for which `fn`
returns nil.
(!!remove (= 0 (% it 2)) '(1 2 3 4)) ;; => '(1 3)
```
+### !keep `(fn list)`
+
+Returns a new list of the non-nil results of applying `fn` to the items in
`list`.
+
+```cl
+(!keep 'cdr '((1 2 3) (4 5) (6))) ;; => '((2 3) (5))
+(!keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6)) ;; => '(40
50 60)
+(!!keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) ;; => '(40 50 60)
+```
+
### !concat `(&rest lists)`
Returns a new list with the concatenation of the elements in
diff --git a/bang.el b/bang.el
index 3022d28..eb23382 100644
--- a/bang.el
+++ b/bang.el
@@ -96,6 +96,22 @@ exposed as `acc`."
"Returns a new list of the items in LIST for which FN returns nil."
(!!remove (funcall fn it) list))
+(defmacro !!keep (form list)
+ "Anaphoric form of `!keep'."
+ `(let ((!--list ,list)
+ (!--result '()))
+ (while !--list
+ (let* ((it (car !--list))
+ (mapped ,form))
+ (when mapped
+ (setq !--result (cons mapped !--result))))
+ (setq !--list (cdr !--list)))
+ (nreverse !--result)))
+
+(defun !keep (fn list)
+ "Returns a new list of the non-nil results of applying FN to the items in
LIST."
+ (!!keep (funcall fn it) list))
+
(defun !concat (&rest lists)
"Returns a new list with the concatenation of the elements in
the supplied LISTS."
diff --git a/examples.el b/examples.el
index 79c23c3..3c4607f 100644
--- a/examples.el
+++ b/examples.el
@@ -40,6 +40,11 @@
(let ((mod 2)) (!remove (lambda (num) (= 0 (% num mod))) '(1 2 3 4))) => '(1
3)
(let ((mod 2)) (!!remove (= 0 (% it mod)) '(1 2 3 4))) => '(1 3))
+(defexamples !keep
+ (!keep 'cdr '((1 2 3) (4 5) (6))) => '((2 3) (5))
+ (!keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6)) => '(40 50
60)
+ (!!keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) => '(40 50 60))
+
(defexamples !concat
(!concat '(1)) => '(1)
(!concat '(1) '(2)) => '(1 2)
- [elpa] externals/dash 657ee8b 040/439: Slight improvements to docs., (continued)
- [elpa] externals/dash 657ee8b 040/439: Slight improvements to docs., Phillip Lord, 2015/08/04
- [elpa] externals/dash 26113a1 041/439: Add pre-commit.sh that runs tests and updates readme., Phillip Lord, 2015/08/04
- [elpa] externals/dash e7d5c01 043/439: Add note about README being autogenerated to Development notes., Phillip Lord, 2015/08/04
- [elpa] externals/dash 32053cd 042/439: Update readme with development notes., Phillip Lord, 2015/08/04
- [elpa] externals/dash e1a362c 047/439: Update README to reflect changes in readme generation., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1b0d54f 044/439: Simplify readme generation., Phillip Lord, 2015/08/04
- [elpa] externals/dash eea3c53 045/439: Move function list above anaphoric function description., Phillip Lord, 2015/08/04
- [elpa] externals/dash 2a9e600 046/439: Make functions paragraph into a list of links, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8bd82c7 051/439: Show empty lists as '() instead of nil in docs., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0912aa2 048/439: Rename !uniq to !distinct, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9312469 053/439: !keep,
Phillip Lord <=
- [elpa] externals/dash 286d1d8 050/439: Show quotes around strings in examples., Phillip Lord, 2015/08/04
- [elpa] externals/dash 24262a1 054/439: Add file-local font-lock for defexamples and =>, Phillip Lord, 2015/08/04
- [elpa] externals/dash f59b480 055/439: Add !some and !every?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2b89641 049/439: Remove needless duplication., Phillip Lord, 2015/08/04
- [elpa] externals/dash b337ef9 052/439: Sync examples-to-docs.el with the one in s.el, Phillip Lord, 2015/08/04
- [elpa] externals/dash db8a745 056/439: Add !each, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6be4c03 058/439: !first, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0991c29 057/439: Added some common aliases, Phillip Lord, 2015/08/04
- [elpa] externals/dash a6323eb 059/439: Add some tests that verify that the lists are evaled by the anaphoric macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash 70488c2 063/439: Add !rpartial, Phillip Lord, 2015/08/04