[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash e47ecb8 187/316: Improve --each-while
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash e47ecb8 187/316: Improve --each-while |
Date: |
Mon, 15 Feb 2021 15:57:56 -0500 (EST) |
branch: externals/dash
commit e47ecb822f6bb10c196ca00030b0e6f5e176495e
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Improve --each-while
* dash.el (--each-while): Optimize and avoid unused lexical variable
byte-compiler warnings.
* dev/examples.el (-each-while): Add more tests.
* README.md:
* dash.info:
* dash.texi: Regenerate docs.
---
README.md | 5 ++--
dash.el | 18 ++++++-------
dash.info | 78 +++++++++++++++++++++++++++++----------------------------
dash.texi | 8 ++++--
dev/examples.el | 8 ++++--
5 files changed, 64 insertions(+), 53 deletions(-)
diff --git a/README.md b/README.md
index 6bb5894..3432319 100644
--- a/README.md
+++ b/README.md
@@ -2571,8 +2571,9 @@ Call `fn` with every item in `list` while (`pred` item)
is non-nil.
Return nil, used for side-effects only.
```el
-(let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (!cons item s))) s) ;;
=> '(4 2)
-(let (s) (--each-while '(1 2 3 4) (< it 3) (!cons it s)) s) ;; => '(2 1)
+(let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (push item s))) s) ;;
=> '(4 2)
+(let (s) (--each-while '(1 2 3 4) (< it 3) (push it s)) s) ;; => '(2 1)
+(let ((s 0)) (--each-while '(1 3 4 5) (odd? it) (setq s (+ s it))) s) ;; => 4
```
#### -each-indexed `(list fn)`
diff --git a/dash.el b/dash.el
index 58cbdef..d57feed 100644
--- a/dash.el
+++ b/dash.el
@@ -109,16 +109,16 @@ See also: `-map-indexed'."
"Anaphoric form of `-each-while'."
(declare (debug (form form body))
(indent 2))
- (let ((l (make-symbol "list"))
- (c (make-symbol "continue")))
+ (let ((l (make-symbol "list")))
`(let ((,l ,list)
- (,c t)
- (it-index 0))
- (while (and ,l ,c)
- (let ((it (car ,l)))
- (if (not ,pred) (setq ,c nil) ,@body))
- (setq it-index (1+ it-index))
- (!cdr ,l)))))
+ (it-index 0)
+ it)
+ (ignore it)
+ (while (when ,l
+ (setq it (pop ,l))
+ ,pred)
+ ,@body
+ (setq it-index (1+ it-index))))))
(defun -each-while (list pred fn)
"Call FN with every item in LIST while (PRED item) is non-nil.
diff --git a/dash.info b/dash.info
index 22bebe4..1e6a14b 100644
--- a/dash.info
+++ b/dash.info
@@ -2485,10 +2485,12 @@ Functions iterating over lists for side-effect only.
Call FN with every item in LIST while (PRED item) is non-nil.
Return nil, used for side-effects only.
- (let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (!cons item
s))) s)
+ (let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (push item
s))) s)
⇒ '(4 2)
- (let (s) (--each-while '(1 2 3 4) (< it 3) (!cons it s)) s)
+ (let (s) (--each-while '(1 2 3 4) (< it 3) (push it s)) s)
⇒ '(2 1)
+ (let ((s 0)) (--each-while '(1 3 4 5) (odd? it) (setq s (+ s it))) s)
+ ⇒ 4
-- Function: -each-indexed (list fn)
Call (FN index item) for each item in LIST.
@@ -3003,7 +3005,7 @@ Index
* !cons: Destructive operations.
(line 6)
* -->: Threading macros. (line 32)
-* --doto: Side-effects. (line 81)
+* --doto: Side-effects. (line 83)
* ->: Threading macros. (line 6)
* ->>: Threading macros. (line 19)
* -all?: Predicates. (line 18)
@@ -3035,15 +3037,15 @@ Index
(line 168)
* -difference: Set operations. (line 20)
* -distinct: Set operations. (line 62)
-* -dotimes: Side-effects. (line 61)
-* -doto: Side-effects. (line 70)
+* -dotimes: Side-effects. (line 63)
+* -doto: Side-effects. (line 72)
* -drop: Sublist selection. (line 125)
* -drop-last: Sublist selection. (line 137)
* -drop-while: Sublist selection. (line 158)
* -each: Side-effects. (line 8)
-* -each-indexed: Side-effects. (line 28)
-* -each-r: Side-effects. (line 41)
-* -each-r-while: Side-effects. (line 52)
+* -each-indexed: Side-effects. (line 30)
+* -each-r: Side-effects. (line 43)
+* -each-r-while: Side-effects. (line 54)
* -each-while: Side-effects. (line 19)
* -elem-index: Indexing. (line 9)
* -elem-indices: Indexing. (line 21)
@@ -3393,36 +3395,36 @@ Ref: -setq82691
Node: Side-effects83507
Ref: -each83701
Ref: -each-while84108
-Ref: -each-indexed84468
-Ref: -each-r84986
-Ref: -each-r-while85419
-Ref: -dotimes85794
-Ref: -doto86097
-Ref: --doto86524
-Node: Destructive operations86799
-Ref: !cons86972
-Ref: !cdr87178
-Node: Function combinators87373
-Ref: -partial87647
-Ref: -rpartial88040
-Ref: -juxt88442
-Ref: -compose88874
-Ref: -applify89432
-Ref: -on89863
-Ref: -flip90389
-Ref: -const90701
-Ref: -cut91045
-Ref: -not91531
-Ref: -orfn91841
-Ref: -andfn92275
-Ref: -iteratefn92770
-Ref: -fixfn93473
-Ref: -prodfn95042
-Node: Development96111
-Node: Contribute96460
-Node: Changes97208
-Node: Contributors100207
-Node: Index101831
+Ref: -each-indexed84566
+Ref: -each-r85084
+Ref: -each-r-while85517
+Ref: -dotimes85892
+Ref: -doto86195
+Ref: --doto86622
+Node: Destructive operations86897
+Ref: !cons87070
+Ref: !cdr87276
+Node: Function combinators87471
+Ref: -partial87745
+Ref: -rpartial88138
+Ref: -juxt88540
+Ref: -compose88972
+Ref: -applify89530
+Ref: -on89961
+Ref: -flip90487
+Ref: -const90799
+Ref: -cut91143
+Ref: -not91629
+Ref: -orfn91939
+Ref: -andfn92373
+Ref: -iteratefn92868
+Ref: -fixfn93571
+Ref: -prodfn95140
+Node: Development96209
+Node: Contribute96558
+Node: Changes97306
+Node: Contributors100305
+Node: Index101929
End Tag Table
diff --git a/dash.texi b/dash.texi
index c6864ee..8a3b73b 100644
--- a/dash.texi
+++ b/dash.texi
@@ -3881,13 +3881,17 @@ Return nil, used for side-effects only.
@example
@group
-(let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (!cons item s))) s)
+(let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (push item s))) s)
@result{} '(4 2)
@end group
@group
-(let (s) (--each-while '(1 2 3 4) (< it 3) (!cons it s)) s)
+(let (s) (--each-while '(1 2 3 4) (< it 3) (push it s)) s)
@result{} '(2 1)
@end group
+@group
+(let ((s 0)) (--each-while '(1 3 4 5) (odd? it) (setq s (+ s it))) s)
+ @result{} 4
+@end group
@end example
@end defun
diff --git a/dev/examples.el b/dev/examples.el
index 4997f5b..04e766f 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -1280,8 +1280,12 @@ new list."
(let (s) (--each (reverse (three-letters)) (setq s (cons it s))) s) =>
'("A" "B" "C"))
(defexamples -each-while
- (let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (!cons item s))) s)
=> '(4 2)
- (let (s) (--each-while '(1 2 3 4) (< it 3) (!cons it s)) s) => '(2 1))
+ (let (s) (-each-while '(2 4 5 6) 'even? (lambda (item) (push item s))) s)
=> '(4 2)
+ (let (s) (--each-while '(1 2 3 4) (< it 3) (push it s)) s) => '(2 1)
+ (let ((s 0)) (--each-while '(1 3 4 5) (odd? it) (setq s (+ s it))) s) => 4
+ (let (s) (--each-while () t (setq s t)) s) => nil
+ (let (s) (--each-while '(1) t (setq s it)) s) => 1
+ (let (s) (--each-while '(1) nil (setq s it)) s) => nil)
(defexamples -each-indexed
(let (s) (-each-indexed '(a b c) (lambda (index item) (setq s (cons (list
item index) s)))) s) => '((c 2) (b 1) (a 0))
- [elpa] externals/dash 42862f3 164/316: Use github actions instead of travis, (continued)
- [elpa] externals/dash 42862f3 164/316: Use github actions instead of travis, ELPA Syncer, 2021/02/15
- [elpa] externals/dash feea52d 174/316: Fix typo, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0f238a9 177/316: Merge pull request #346 from jcs-PR/badge, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 52fd010 167/316: feat: add -zip-lists, ELPA Syncer, 2021/02/15
- [elpa] externals/dash be03404 179/316: Fix package keywords, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b92ab5a 175/316: Merge branch 'zaeph/fix-typo', ELPA Syncer, 2021/02/15
- [elpa] externals/dash eb0a94f 178/316: Update docs after incorporating README.md change, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 732d92e 173/316: Remove duplicate definition., ELPA Syncer, 2021/02/15
- [elpa] externals/dash b1bc1bf 181/316: Use correct names of package archives, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f2c0e0d 184/316: Add dash-fontify-mode, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e47ecb8 187/316: Improve --each-while,
ELPA Syncer <=
- [elpa] externals/dash 081e10a 192/316: Improve take/drop definitions, ELPA Syncer, 2021/02/15
- [elpa] externals/dash aa76fb3 201/316: Copy-edit README, ELPA Syncer, 2021/02/15
- [elpa] externals/dash ac1f66a 215/316: ; Fix omission in last change, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8c47f17 038/316: Add function signatures for aliases of built-in functions (#201), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 38d44ed 128/316: Implement --doto, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6514359 126/316: Merge pull request #264 from basil-conto/blc/reduce, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 258c324 140/316: Release 2.16.0, ELPA Syncer, 2021/02/15
- [elpa] externals/dash fdf6140 158/316: Merge pull request #322 from wbolster/zip-pair-doc-clarification, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 721436b 168/316: chore: release 2.17.0, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 562084e 171/316: Fix another typo and its copies, ELPA Syncer, 2021/02/15