[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 506401e 203/426: Merge pull request #39 from Fuco1
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 506401e 203/426: Merge pull request #39 from Fuco1/rotate |
Date: |
Tue, 04 Aug 2015 19:37:44 +0000 |
branch: externals/dash
commit 506401e8397e2e5d5d8943ec9ad6e3b7e61b05b4
Merge: 970728e 9bd656e
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Merge pull request #39 from Fuco1/rotate
Add -rotate
---
README.md | 11 +++++++++++
dash.el | 8 ++++++++
dev/examples.el | 4 ++++
3 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 1d1e4c8..8387977 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-take-while](#-take-while-pred-list) `(pred list)`
* [-drop-while](#-drop-while-pred-list) `(pred list)`
* [-split-at](#-split-at-n-list) `(n list)`
+* [-rotate](#-rotate-n-list) `(n list)`
* [-insert-at](#-insert-at-n-x-list) `(n x list)`
* [-split-with](#-split-with-pred-list) `(pred list)`
* [-separate](#-separate-pred-list) `(pred list)`
@@ -502,6 +503,16 @@ Returns a list of ((-take `n` `list`) (-drop `n` `list`)),
in no more than one p
(-split-at 17 '(1 2 3 4 5)) ;; => '((1 2 3 4 5) nil)
```
+### -rotate `(n list)`
+
+Rotate `list` `n` places to the right. With `n` negative, rotate to the left.
+The time complexity is `o`(n).
+
+```cl
+(-rotate 3 '(1 2 3 4 5 6 7)) ;; => '(5 6 7 1 2 3 4)
+(-rotate -3 '(1 2 3 4 5 6 7)) ;; => '(4 5 6 7 1 2 3)
+```
+
### -insert-at `(n x list)`
Returns a list with `x` inserted into `list` at position `n`.
diff --git a/dash.el b/dash.el
index 093ccd6..7e2618a 100644
--- a/dash.el
+++ b/dash.el
@@ -450,6 +450,13 @@ FROM or TO may be negative."
(!cdr list)))
(list (nreverse result) list)))
+(defun -rotate (n list)
+ "Rotate LIST N places to the right. With N negative, rotate to the left.
+The time complexity is O(n)."
+ (if (> n 0)
+ (append (last list n) (butlast list n))
+ (append (-drop (- n) list) (-take (- n) list))))
+
(defun -insert-at (n x list)
"Returns a list with X inserted into LIST at position N."
(let ((split-list (-split-at n list)))
@@ -1001,6 +1008,7 @@ Returns nil if N is less than 1."
"--drop-while"
"-drop-while"
"-split-at"
+ "-rotate"
"-insert-at"
"--split-with"
"-split-with"
diff --git a/dev/examples.el b/dev/examples.el
index 06105bd..b2fe1bf 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -199,6 +199,10 @@
(-split-at 3 '(1 2 3 4 5)) => '((1 2 3) (4 5))
(-split-at 17 '(1 2 3 4 5)) => '((1 2 3 4 5) nil))
+(defexamples -rotate
+ (-rotate 3 '(1 2 3 4 5 6 7)) => '(5 6 7 1 2 3 4)
+ (-rotate -3 '(1 2 3 4 5 6 7)) => '(4 5 6 7 1 2 3))
+
(defexamples -insert-at
(-insert-at 1 'x '(a b c)) => '(a x b c)
(-insert-at 12 'x '(a b c)) => '(a b c x))
- [elpa] externals/dash 3226100 194/426: Indent according to emacs lisp standard, (continued)
- [elpa] externals/dash 3226100 194/426: Indent according to emacs lisp standard, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9f156a6 193/426: Release 1.5.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash a3faf7c 183/426: Release 1.3.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash e07cef6 196/426: Adding -first-item and -last-item. [magnars/dash.el#17], Phillip Lord, 2015/08/04
- [elpa] externals/dash 50659cc 189/426: Release 1.4.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4164908 197/426: Add -min, -max, -min-by and -max-by., Phillip Lord, 2015/08/04
- [elpa] externals/dash 2b20088 195/426: Add -juxt, Phillip Lord, 2015/08/04
- [elpa] externals/dash a3b2fdb 198/426: Merge pull request #38 from rejeep/min-and-max, Phillip Lord, 2015/08/04
- [elpa] externals/dash 22d2c2d 199/426: Release 1.6.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash b0ff280 205/426: Updating docs--signature to handle aliases and subrs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 506401e 203/426: Merge pull request #39 from Fuco1/rotate,
Phillip Lord <=
- [elpa] externals/dash 5b5dab5 200/426: Fix typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9bd656e 202/426: Add -rotate, Phillip Lord, 2015/08/04
- [elpa] externals/dash 970728e 201/426: Actually update README :P, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8b17154 204/426: Release 1.7.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0db2f5a 208/426: Fix second example for -last/first-item, Phillip Lord, 2015/08/04
- [elpa] externals/dash 788573e 206/426: Merge pull request #36 from Wilfred/master, Phillip Lord, 2015/08/04
- [elpa] externals/dash b1cfe18 209/426: Fix incorrect alias checking in docs--signature, Phillip Lord, 2015/08/04
- [elpa] externals/dash 37064b5 213/426: Include @Fuco1 in Authors/Copyright + fix README, Phillip Lord, 2015/08/04
- [elpa] externals/dash 824fcb3 207/426: Release 1.8.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash d6ca7d9 215/426: Fix E23 bug and re-enable E23 CI, Phillip Lord, 2015/08/04