Simplify -non-nil

* dash.el (-non-nil): Use --filter for speed.
* dev/examples.el (-non-nil): Extend tests.

* README.md:
* dash.texi: Regenerate docs.
master
Basil L. Contovounesios 5 years ago
parent f3ae7bb615
commit 0e5acda7a5
No known key found for this signature in database
GPG Key ID: 205AB54A5D5D8CFF
  1. 6
      README.md
  2. 4
      dash.el
  3. 12
      dash.texi
  4. 7
      dev/examples.el

@ -586,10 +586,12 @@ The comparison is done with `equal`.
#### -non-nil `(list)`
Return all non-nil elements of `list`.
Return a copy of `list` with all nil items removed.
```el
(-non-nil '(1 nil 2 nil nil 3 4 nil 5 nil)) ;; => '(1 2 3 4 5)
(-non-nil '(nil 1 nil 2 nil nil 3 4 nil 5 nil)) ;; => '(1 2 3 4 5)
(-non-nil '((nil))) ;; => '((nil))
(-non-nil '()) ;; => '()
```
#### -slice `(list from &optional to step)`

@ -530,9 +530,9 @@ If you want to select the original items satisfying a predicate use `-filter'."
(--keep (funcall fn it) list))
(defun -non-nil (list)
"Return all non-nil elements of LIST."
"Return a copy of LIST with all nil items removed."
(declare (pure t) (side-effect-free t))
(-remove 'null list))
(--filter it list))
(defmacro --map-indexed (form list)
"Anaphoric form of `-map-indexed'."

@ -603,13 +603,21 @@ The comparison is done with @code{equal}.
@anchor{-non-nil}
@defun -non-nil (list)
Return all non-nil elements of @var{list}.
Return a copy of @var{list} with all nil items removed.
@example
@group
(-non-nil '(1 nil 2 nil nil 3 4 nil 5 nil))
(-non-nil '(nil 1 nil 2 nil nil 3 4 nil 5 nil))
@result{} '(1 2 3 4 5)
@end group
@group
(-non-nil '((nil)))
@result{} '((nil))
@end group
@group
(-non-nil '())
@result{} '()
@end group
@end example
@end defun

@ -209,7 +209,12 @@ new list."
(let ((l (list 1 2))) (setcar (-remove-item 2 l) 0) l) => '(1 2))
(defexamples -non-nil
(-non-nil '(1 nil 2 nil nil 3 4 nil 5 nil)) => '(1 2 3 4 5))
(-non-nil '(nil 1 nil 2 nil nil 3 4 nil 5 nil)) => '(1 2 3 4 5)
(-non-nil '((()))) => '((()))
(-non-nil '()) => '()
(let ((l (list 1 2))) (setcar (-non-nil l) 0) l) => '(1 2)
(let ((l (list nil 1))) (setcar (-non-nil l) 0) l) => '(nil 1)
(let ((l (list 1 nil))) (setcar (-non-nil l) 0) l) => '(1 nil))
(defexamples -slice
(-slice '(1 2 3 4 5) 1) => '(2 3 4 5)

Loading…
Cancel
Save