[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 609b7e7 2/3: Clean up --partition-after-pred
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 609b7e7 2/3: Clean up --partition-after-pred |
Date: |
Wed, 2 Jun 2021 15:57:12 -0400 (EDT) |
branch: externals/dash
commit 609b7e7d62b16a8f0259adf430236cb0202deac6
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Clean up --partition-after-pred
* dash.el (--partition-after-pred): Simplify. Extend docstring.
(-partition-after-pred): Extend docstring.
* dev/examples.el (-partition-after-pred): Extend tests.
* README.md:
* dash.texi: Regenerate docs.
Re: #362.
---
README.md | 4 +++-
dash.el | 38 ++++++++++++++++++++------------------
dash.texi | 4 +++-
dev/examples.el | 20 ++++++++++++++++++--
4 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/README.md b/README.md
index 40d1a4e..0d9f7e3 100644
--- a/README.md
+++ b/README.md
@@ -1540,7 +1540,9 @@ other value (the body).
#### -partition-after-pred `(pred list)`
-Partition directly after each time `pred` is true on an element of `list`.
+Partition `list` after each element for which `pred` returns non-nil.
+
+This function's anaphoric counterpart is `--partition-after-pred`.
```el
(-partition-after-pred #'booleanp ()) ;; => ()
diff --git a/dash.el b/dash.el
index 69c474b..3b5dd5b 100644
--- a/dash.el
+++ b/dash.el
@@ -1383,27 +1383,29 @@ other value (the body)."
(--partition-by-header (funcall fn it) list))
(defmacro --partition-after-pred (form list)
- "Anaphoric form of `-partition-after-pred'."
- (let ((r (make-symbol "result"))
- (s (make-symbol "sublist"))
- (l (make-symbol "list")))
- `(let ((,l ,list))
+ "Partition LIST after each element for which FORM evaluates to non-nil.
+Each element of LIST in turn is bound to `it' before evaluating
+FORM.
+
+This is the anaphoric counterpart to `-partition-after-pred'."
+ (let ((l (make-symbol "list"))
+ (r (make-symbol "result"))
+ (s (make-symbol "sublist")))
+ `(let ((,l ,list) ,r ,s)
(when ,l
- (let* ((,r nil)
- (,s nil))
- (while ,l
- (let* ((it (car ,l)))
- (!cdr ,l)
- (!cons it ,s)
- (when ,form
- (!cons (nreverse ,s) ,r)
- (setq ,s nil))))
- (if ,s
- (!cons (nreverse ,s) ,r))
- (nreverse ,r))))))
+ (--each ,l
+ (push it ,s)
+ (when ,form
+ (push (nreverse ,s) ,r)
+ (setq ,s ())))
+ (when ,s
+ (push (nreverse ,s) ,r))
+ (nreverse ,r)))))
(defun -partition-after-pred (pred list)
- "Partition directly after each time PRED is true on an element of LIST."
+ "Partition LIST after each element for which PRED returns non-nil.
+
+This function's anaphoric counterpart is `--partition-after-pred'."
(--partition-after-pred (funcall pred it) list))
(defun -partition-before-pred (pred list)
diff --git a/dash.texi b/dash.texi
index 60aabb4..70e782a 100644
--- a/dash.texi
+++ b/dash.texi
@@ -2197,7 +2197,9 @@ other value (the body).
@anchor{-partition-after-pred}
@defun -partition-after-pred (pred list)
-Partition directly after each time @var{pred} is true on an element of
@var{list}.
+Partition @var{list} after each element for which @var{pred} returns non-nil.
+
+This function's anaphoric counterpart is @code{--partition-after-pred}.
@example
@group
diff --git a/dev/examples.el b/dev/examples.el
index 81d6da9..df05d34 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -807,8 +807,24 @@ value rather than consuming a list to produce a single
value."
(-partition-after-pred #'booleanp '(0 0 t t 0 t)) => '((0 0 t) (t) (0 t))
(-partition-after-pred #'booleanp '(t)) => '((t))
(-partition-after-pred #'booleanp '(0 t)) => '((0 t))
- (--partition-after-pred (= 1 (% it 2)) '(0 0 0 1 0 1 1 0 1))
- => '((0 0 0 1) (0 1) (1) (0 1)))
+ (--partition-after-pred (= (% it 2) 0) '()) => '()
+ (--partition-after-pred (= (% it 2) 1) '()) => '()
+ (--partition-after-pred (= (% it 2) 0) '(0)) => '((0))
+ (--partition-after-pred (= (% it 2) 1) '(0)) => '((0))
+ (--partition-after-pred (= (% it 2) 0) '(0 1)) => '((0) (1))
+ (--partition-after-pred (= (% it 2) 1) '(0 1)) => '((0 1))
+ (--partition-after-pred (= (% it 2) 0) '(0 1 2)) => '((0) (1 2))
+ (--partition-after-pred (= (% it 2) 1) '(0 1 2)) => '((0 1) (2))
+ (--partition-after-pred (= (% it 2) 0) '(0 1 2 3)) => '((0) (1 2) (3))
+ (--partition-after-pred (= (% it 2) 1) '(0 1 2 3)) => '((0 1) (2 3))
+ (--partition-after-pred t '()) => ()
+ (--partition-after-pred t '(0)) => '((0))
+ (--partition-after-pred t '(0 1)) => '((0) (1))
+ (--partition-after-pred t '(0 1 2)) => '((0) (1) (2))
+ (--partition-after-pred nil '()) => '()
+ (--partition-after-pred nil '(0)) => '((0))
+ (--partition-after-pred nil '(0 1)) => '((0 1))
+ (--partition-after-pred nil '(0 1 2)) => '((0 1 2)))
(defexamples -partition-before-pred
(-partition-before-pred #'booleanp '()) => '()