[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash a196ac1 137/426: Fix -repeat
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash a196ac1 137/426: Fix -repeat |
Date: |
Tue, 04 Aug 2015 19:37:14 +0000 |
branch: externals/dash
commit a196ac11660dbb1dc66fbae7e420fd4e8cec8339
Author: vemv <address@hidden>
Commit: vemv <address@hidden>
Fix -repeat
---
README.md | 12 ++++++++++++
dash.el | 13 +++++++------
dev/examples.el | 6 ++++++
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 3b030b2..dc25b20 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-->](#---x-form-rest-more) `(x form &rest more)`
* [!cons](#-cons-car-cdr) `(car cdr)`
* [!cdr](#-cdr-list) `(list)`
+* [-repeat](#-repeat-n-x) `(n x)`
There are also anaphoric versions of these functions where that makes sense,
prefixed with two dashes instead of one.
@@ -586,6 +587,17 @@ Destructive: Sets `list` to the cdr of `list`.
(let ((l '(3 5))) (!cdr l) l) ;; => '(5)
```
+### -repeat `(n x)`
+
+Return a list of `n` Xs.
+Attempts of retrieving a non-positive amount of Xs will return nil.
+
+```cl
+(-repeat 3 :a) ;; => '(:a :a :a)
+(-repeat 1 :a) ;; => '(:a)
+(-repeat 0 :a) ;; => nil
+```
+
## Contribute
diff --git a/dash.el b/dash.el
index b1b5896f..a67b957 100644
--- a/dash.el
+++ b/dash.el
@@ -587,15 +587,16 @@ or with `-compare-fn' if that's non-nil."
(setq lst (cdr lst)))
lst))))))
+(defalias '-contains-p '-contains?)
+
(defun -repeat (n x)
- "Return a list of N Xs."
+ "Return a list of N Xs.
+Attempts of retrieving a non-positive amount of Xs will return nil."
(let ((ret nil))
- (loop for i from 0 to (dec n) do
- (setq ret (cons x ret)))
+ (while (not (minusp (setq n (1- n))))
+ (!cons x ret))
ret))
-(defalias '-contains-p '-contains?)
-
(eval-after-load "lisp-mode"
'(progn
(let ((new-keywords '(
@@ -678,7 +679,7 @@ or with `-compare-fn' if that's non-nil."
"-difference"
"-contains?"
"-contains-p"
- ))
+ "-repeat"))
(special-variables '(
"it"
"it-index"
diff --git a/dev/examples.el b/dev/examples.el
index e9686ac..d5d5b80 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -239,3 +239,9 @@
(defexamples !cdr
(let ((l '(3))) (!cdr l) l) => '()
(let ((l '(3 5))) (!cdr l) l) => '(5))
+
+(defexamples -repeat
+ (-repeat 3 :a) => '(:a :a :a)
+ (-repeat 1 :a) => '(:a)
+ (-repeat 0 :a) => nil
+ (-repeat -1 :a) => nil)
- [elpa] externals/dash 85bd4e0 131/426: Add @tali713's -applify, (continued)
- [elpa] externals/dash 85bd4e0 131/426: Add @tali713's -applify, Phillip Lord, 2015/08/04
- [elpa] externals/dash e9de223 116/426: Rename -replace-where to -map-when, Phillip Lord, 2015/08/04
- [elpa] externals/dash 002e4cd 132/426: Add tali713 to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 7e4ee06 135/426: 1.0.3, Phillip Lord, 2015/08/04
- [elpa] externals/dash e4521af 136/426: Add -repeat, Phillip Lord, 2015/08/04
- [elpa] externals/dash 69e054e 124/426: Switch around order of Contribute and Contributors parts in readme., Phillip Lord, 2015/08/04
- [elpa] externals/dash 78390f6 139/426: Merge pull request #12 from vemv/master, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1284bc6 134/426: Move .el files out of root., Phillip Lord, 2015/08/04
- [elpa] externals/dash da8dc62 138/426: Preserve newline at new-keywords, Phillip Lord, 2015/08/04
- [elpa] externals/dash 467dfa7 133/426: Add -map-indexed, Phillip Lord, 2015/08/04
- [elpa] externals/dash a196ac1 137/426: Fix -repeat,
Phillip Lord <=
- [elpa] externals/dash 9c5fbc5 143/426: nil is the default binding in let forms, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8fe15ed 141/426: Group -repeat with -dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 98a82ca 142/426: DRY up -repeat with --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 50e9f46 144/426: -cons* for making improper lists., Phillip Lord, 2015/08/04
- [elpa] externals/dash e083087 145/426: Merge pull request #13 from nicferrier/master, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5161361 148/426: Clarify use of anaphoric form of -zip-with, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0731333 140/426: Add @vemv to list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash a7ee06e 149/426: Remove extra --separate definition, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3f604cd 151/426: Add -count, Phillip Lord, 2015/08/04
- [elpa] externals/dash fb75a7f 146/426: Add @nicferrier to list of contributors., Phillip Lord, 2015/08/04