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

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

[elpa] externals/dash 8c75026 080/439: Add !drop


From: Phillip Lord
Subject: [elpa] externals/dash 8c75026 080/439: Add !drop
Date: Tue, 04 Aug 2015 20:26:37 +0000

branch: externals/dash
commit 8c750265762933dd9a3b6a7417f232b0399f4a1d
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Add !drop
---
 README.md   |   10 ++++++++++
 bang.el     |    7 +++++++
 examples.el |    4 ++++
 3 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md
index 98f1ea3..8ff0a3f 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](#take-n-list) `(n list)`
+* [!drop](#drop-n-list) `(n list)`
 * [!take-while](#take-while-fn-list) `(fn list)`
 * [!drop-while](#drop-while-fn-list) `(fn list)`
 * [!split-with](#split-with-fn-list) `(fn list)`
@@ -175,6 +176,15 @@ Returns a new list of the first `n` items in `list`, or 
all items if there are f
 (!take 17 '(1 2 3 4 5)) ;; => '(1 2 3 4 5)
 ```
 
+### !drop `(n list)`
+
+Returns the tail of `list` without the first `n` items.
+
+```cl
+(!drop 3 '(1 2 3 4 5)) ;; => '(4 5)
+(!drop 17 '(1 2 3 4 5)) ;; => '()
+```
+
 ### !take-while `(fn list)`
 
 Returns a new list of successive items from `list` while (`fn` item) returns a 
non-nil value.
diff --git a/bang.el b/bang.el
index 4320a74..f52caef 100644
--- a/bang.el
+++ b/bang.el
@@ -153,6 +153,13 @@ Thus function FN should return a collection."
       (setq n (1- n)))
     (nreverse result)))
 
+(defun !drop (n list)
+  "Returns the tail of LIST without the first N items."
+  (while (and list (> n 0))
+    (setq list (cdr list))
+    (setq n (1- n)))
+  list)
+
 (defmacro !!take-while (form list)
   "Anaphoric form of `!take-while'."
   (let ((l (make-symbol "list"))
diff --git a/examples.el b/examples.el
index c08d46b..01c3b15 100644
--- a/examples.el
+++ b/examples.el
@@ -62,6 +62,10 @@
   (!take 3 '(1 2 3 4 5)) => '(1 2 3)
   (!take 17 '(1 2 3 4 5)) => '(1 2 3 4 5))
 
+(defexamples !drop
+  (!drop 3 '(1 2 3 4 5)) => '(4 5)
+  (!drop 17 '(1 2 3 4 5)) => '())
+
 (defexamples !take-while
   (!take-while 'even? '(1 2 3 4)) => '()
   (!take-while 'even? '(2 4 5 6)) => '(2 4)



reply via email to

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