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

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

[elpa] externals/dash 78390f6 139/426: Merge pull request #12 from vemv/


From: Phillip Lord
Subject: [elpa] externals/dash 78390f6 139/426: Merge pull request #12 from vemv/master
Date: Tue, 04 Aug 2015 19:37:14 +0000

branch: externals/dash
commit 78390f6e29011224e3c969a82a7e36cdc2f8ce8b
Merge: 7e4ee06 da8dc62
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Merge pull request #12 from vemv/master
    
    Add -repeat
---
 README.md       |   12 ++++++++++++
 dash.el         |    9 +++++++++
 dev/examples.el |    6 ++++++
 3 files changed, 27 insertions(+), 0 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 2eebff8..04dde4e 100644
--- a/dash.el
+++ b/dash.el
@@ -589,6 +589,14 @@ or with `-compare-fn' if that's non-nil."
 
 (defalias '-contains-p '-contains?)
 
+(defun -repeat (n x)
+  "Return a list of N Xs.
+Attempts of retrieving a non-positive amount of Xs will return nil."
+  (let ((ret nil))
+    (while (not (minusp (setq n (1- n))))
+      (!cons x ret))
+    ret))
+
 (eval-after-load "lisp-mode"
   '(progn
      (let ((new-keywords '(
@@ -671,6 +679,7 @@ or with `-compare-fn' if that's non-nil."
                            "-difference"
                            "-contains?"
                            "-contains-p"
+                           "-repeat"
                            ))
            (special-variables '(
                                 "it"
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)



reply via email to

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