emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash 3adad97 334/439: Add -non-nil


From: Phillip Lord
Subject: [elpa] externals/dash 3adad97 334/439: Add -non-nil
Date: Tue, 04 Aug 2015 20:29:53 +0000

branch: externals/dash
commit 3adad97d371be9a875f48f8d926c437a7d6c7f6b
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>

    Add -non-nil
---
 README.md       |    9 +++++++++
 dash.el         |    5 +++++
 dev/examples.el |    3 +++
 3 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md
index 2e58b9d..d30cd76 100644
--- a/README.md
+++ b/README.md
@@ -59,6 +59,7 @@ Functions returning a sublist of the original list.
 
 * [-filter](#-filter-pred-list) `(pred list)`
 * [-remove](#-remove-pred-list) `(pred list)`
+* [-non-nil](#-non-nil-list) `(list)`
 * [-slice](#-slice-list-from-optional-to-step) `(list from &optional to step)`
 * [-take](#-take-n-list) `(n list)`
 * [-drop](#-drop-n-list) `(n list)`
@@ -411,6 +412,14 @@ Alias: `-reject`
 (--remove (= 0 (% it 2)) '(1 2 3 4)) ;; => '(1 3)
 ```
 
+#### -non-nil `(list)`
+
+Return all non-nil elements of `list`.
+
+```cl
+(-non-nil '(1 nil 2 nil nil 3 4 nil 5 nil)) ;; => '(1 2 3 4 5)
+```
+
 #### -slice `(list from &optional to step)`
 
 Return copy of `list`, starting from index `from` to index `to`.
diff --git a/dash.el b/dash.el
index 43e0349..76a8e75 100644
--- a/dash.el
+++ b/dash.el
@@ -239,6 +239,10 @@ Alias: `-reject'"
   "Return a new list of the non-nil results of applying FN to the items in 
LIST."
   (--keep (funcall fn it) list))
 
+(defun -non-nil (list)
+  "Return all non-nil elements of LIST."
+  (-remove 'null list))
+
 (defmacro --map-indexed (form list)
   "Anaphoric form of `-map-indexed'."
   (declare (debug (form form)))
@@ -1579,6 +1583,7 @@ structure such as plist or alist."
                              "--remove"
                              "-reject"
                              "--reject"
+                             "-non-nil"
                              "-keep"
                              "--keep"
                              "-map-indexed"
diff --git a/dev/examples.el b/dev/examples.el
index fba6639..5e1197d 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -69,6 +69,9 @@ new list."
     (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 -non-nil
+    (-non-nil '(1 nil 2 nil nil 3 4 nil 5 nil)) => '(1 2 3 4 5))
+
   (defexamples -slice
     (-slice '(1 2 3 4 5) 1) => '(2 3 4 5)
     (-slice '(1 2 3 4 5) 0 3) => '(1 2 3)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]