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

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

[elpa] externals/dash 82a12a2 076/426: Add !drop-while


From: Phillip Lord
Subject: [elpa] externals/dash 82a12a2 076/426: Add !drop-while
Date: Tue, 04 Aug 2015 19:36:49 +0000

branch: externals/dash
commit 82a12a251f312810f008cacc5a254b332b91e7cf
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Add !drop-while
---
 README.md   |   11 +++++++++++
 bang.el     |   12 ++++++++++++
 examples.el |    5 +++++
 3 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md
index 15da0c9..0370383 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,7 @@ Or you can just dump `bang.el` in your load path somewhere.
 * [!concat](#concat-rest-lists) `(&rest lists)`
 * [!mapcat](#mapcat-fn-list) `(fn list)`
 * [!take-while](#take-while-fn-list) `(fn list)`
+* [!drop-while](#drop-while-fn-list) `(fn list)`
 * [!interpose](#interpose-sep-list) `(sep list)`
 * [!replace-where](#replace-where-pred-rep-list) `(pred rep list)`
 * [!first](#first-fn-list) `(fn list)`
@@ -173,6 +174,16 @@ Returns a new list of successive items from `list` while 
(`fn` item) returns a n
 (!!take-while (< it 4) '(1 2 3 4 3 2 1)) ;; => '(1 2 3)
 ```
 
+### !drop-while `(fn list)`
+
+Returns the tail of `list` starting from the first item for which (`fn` item) 
returns nil.
+
+```cl
+(!drop-while 'even? '(1 2 3 4)) ;; => '(1 2 3 4)
+(!drop-while 'even? '(2 4 5 6)) ;; => '(5 6)
+(!!drop-while (< it 4) '(1 2 3 4 3 2 1)) ;; => '(4 3 2 1)
+```
+
 ### !interpose `(sep list)`
 
 Returns a new list of all elements in `list` separated by `sep`.
diff --git a/bang.el b/bang.el
index 4fc290f..0cd4c0f 100644
--- a/bang.el
+++ b/bang.el
@@ -159,6 +159,18 @@ Thus function FN should return a collection."
   "Returns a new list of successive items from LIST while (FN item) returns a 
non-nil value."
   (!!take-while (funcall fn it) list))
 
+(defmacro !!drop-while (form list)
+  "Anaphoric form of `!drop-while'."
+  (let ((l (make-symbol "list")))
+    `(let ((,l ,list))
+       (while (and ,l (let ((it (car ,l))) ,form))
+         (setq ,l (cdr ,l)))
+       ,l)))
+
+(defun !drop-while (fn list)
+  "Returns the tail of LIST starting from the first item for which (FN item) 
returns nil."
+  (!!drop-while (funcall fn it) list))
+
 (defun !interpose (sep list)
   "Returns a new list of all elements in LIST separated by SEP."
   (let (result)
diff --git a/examples.el b/examples.el
index 32f9221..c2578b3 100644
--- a/examples.el
+++ b/examples.el
@@ -63,6 +63,11 @@
   (!take-while 'even? '(2 4 5 6)) => '(2 4)
   (!!take-while (< it 4) '(1 2 3 4 3 2 1)) => '(1 2 3))
 
+(defexamples !drop-while
+  (!drop-while 'even? '(1 2 3 4)) => '(1 2 3 4)
+  (!drop-while 'even? '(2 4 5 6)) => '(5 6)
+  (!!drop-while (< it 4) '(1 2 3 4 3 2 1)) => '(4 3 2 1))
+
 (defexamples !interpose
   (!interpose "-" '()) => '()
   (!interpose "-" '("a")) => '("a")



reply via email to

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