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.
master
Basil L. Contovounesios 5 years ago
parent b540ebb9d6
commit 609b7e7d62
No known key found for this signature in database
GPG Key ID: 205AB54A5D5D8CFF
  1. 4
      README.md
  2. 38
      dash.el
  3. 4
      dash.texi
  4. 20
      dev/examples.el

@ -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 ()) ;; => ()

@ -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)

@ -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

@ -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 '()) => '()

Loading…
Cancel
Save