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

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

[elpa] externals/dash 0ac1ecf6b5 3/3: Recategorize -repeat and -cycle as


From: ELPA Syncer
Subject: [elpa] externals/dash 0ac1ecf6b5 3/3: Recategorize -repeat and -cycle as unfolds
Date: Wed, 8 Jun 2022 15:57:34 -0400 (EDT)

branch: externals/dash
commit 0ac1ecf6b56eb67bb81a3cf70f8d4354b5782341
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Recategorize -repeat and -cycle as unfolds
    
    * dash.el (-repeat): Use >= in place of natnump, for speed.
    * dev/examples.el (-repeat, -cycle): Move from "Other list
    operations" to "Unfolding".
    
    * README.md:
    * dash.texi: Regenerate docs.
---
 README.md       | 50 ++++++++++++++++-----------------
 dash.el         |  2 +-
 dash.texi       | 86 ++++++++++++++++++++++++++++-----------------------------
 dev/examples.el | 34 +++++++++++++----------
 4 files changed, 88 insertions(+), 84 deletions(-)

diff --git a/README.md b/README.md
index 43efd00539..7351eb43d5 100644
--- a/README.md
+++ b/README.md
@@ -211,6 +211,8 @@ value rather than consuming a list to produce a single 
value.
 
 * [`-iterate`](#-iterate-fun-init-n) `(fun init n)`
 * [`-unfold`](#-unfold-fun-seed) `(fun seed)`
+* [`-repeat`](#-repeat-n-x) `(n x)`
+* [`-cycle`](#-cycle-list) `(list)`
 
 ### Predicates
 
@@ -279,7 +281,6 @@ Operations pretending lists are sets.
 Other list functions not fit to be classified elsewhere.
 
 * [`-rotate`](#-rotate-n-list) `(n list)`
-* [`-repeat`](#-repeat-n-x) `(n x)`
 * [`-cons*`](#-cons-rest-args) `(&rest args)`
 * [`-snoc`](#-snoc-list-elem-rest-elements) `(list elem &rest elements)`
 * [`-interpose`](#-interpose-sep-list) `(sep list)`
@@ -290,7 +291,6 @@ Other list functions not fit to be classified elsewhere.
 * [`-zip-lists`](#-zip-lists-rest-lists) `(&rest lists)`
 * [`-zip-fill`](#-zip-fill-fill-value-rest-lists) `(fill-value &rest lists)`
 * [`-unzip`](#-unzip-lists) `(lists)`
-* [`-cycle`](#-cycle-list) `(list)`
 * [`-pad`](#-pad-fill-value-rest-lists) `(fill-value &rest lists)`
 * [`-table`](#-table-fn-rest-lists) `(fn &rest lists)`
 * [`-table-flat`](#-table-flat-fn-rest-lists) `(fn &rest lists)`
@@ -1304,6 +1304,29 @@ the new seed.
 (--unfold (when it (cons it (butlast it))) '(1 2 3 4)) ;; => ((1 2 3 4) (1 2 
3) (1 2) (1))
 ```
 
+#### -repeat `(n x)`
+
+Return a new list of length `n` with each element being `x`.
+Return `nil` if `n` is less than 1.
+
+```el
+(-repeat 3 :a) ;; => (:a :a :a)
+(-repeat 1 :a) ;; => (:a)
+(-repeat 0 :a) ;; => ()
+```
+
+#### -cycle `(list)`
+
+Return an infinite circular copy of `list`.
+The returned list cycles through the elements of `list` and repeats
+from the beginning.
+
+```el
+(-take 5 (-cycle '(1 2 3))) ;; => (1 2 3 1 2)
+(-take 7 (-cycle '(1 "and" 3))) ;; => (1 "and" 3 1 "and" 3 1)
+(-zip (-cycle '(1 2 3)) '(1 2)) ;; => ((1 . 1) (2 . 2))
+```
+
 ## Predicates
 
 Reductions of one or more lists to a boolean value.
@@ -1894,17 +1917,6 @@ The time complexity is O(n).
 (-rotate 16 '(1 2 3 4 5 6 7)) ;; => (6 7 1 2 3 4 5)
 ```
 
-#### -repeat `(n x)`
-
-Return a new list of length `n` with each element being `x`.
-Return `nil` if `n` is less than 1.
-
-```el
-(-repeat 3 :a) ;; => (:a :a :a)
-(-repeat 1 :a) ;; => (:a)
-(-repeat 0 :a) ;; => nil
-```
-
 #### -cons* `(&rest args)`
 
 Make a new list from the elements of `args`.
@@ -2054,18 +2066,6 @@ See also: [`-zip`](#-zip-rest-lists)
 (-unzip '((1 2) (3 4))) ;; => ((1 . 3) (2 . 4))
 ```
 
-#### -cycle `(list)`
-
-Return an infinite circular copy of `list`.
-The returned list cycles through the elements of `list` and repeats
-from the beginning.
-
-```el
-(-take 5 (-cycle '(1 2 3))) ;; => (1 2 3 1 2)
-(-take 7 (-cycle '(1 "and" 3))) ;; => (1 "and" 3 1 "and" 3 1)
-(-zip (-cycle '(1 2 3)) '(1 2)) ;; => ((1 . 1) (2 . 2))
-```
-
 #### -pad `(fill-value &rest lists)`
 
 Pad each of `lists` with `fill-value` until they all have equal lengths.
diff --git a/dash.el b/dash.el
index 3447016eeb..e04201ff22 100644
--- a/dash.el
+++ b/dash.el
@@ -3143,7 +3143,7 @@ backward compatibility and is otherwise deprecated."
   "Return a new list of length N with each element being X.
 Return nil if N is less than 1."
   (declare (pure t) (side-effect-free t))
-  (and (natnump n) (make-list n x)))
+  (and (>= n 0) (make-list n x)))
 
 (defun -sum (list)
   "Return the sum of LIST."
diff --git a/dash.texi b/dash.texi
index 72b7b712ca..a868cfddad 100644
--- a/dash.texi
+++ b/dash.texi
@@ -1756,6 +1756,49 @@ the new seed.
 @end example
 @end defun
 
+@anchor{-repeat}
+@defun -repeat (n x)
+Return a new list of length @var{n} with each element being @var{x}.
+Return @code{nil} if @var{n} is less than 1.
+
+@example
+@group
+(-repeat 3 :a)
+    @result{} (:a :a :a)
+@end group
+@group
+(-repeat 1 :a)
+    @result{} (:a)
+@end group
+@group
+(-repeat 0 :a)
+    @result{} ()
+@end group
+@end example
+@end defun
+
+@anchor{-cycle}
+@defun -cycle (list)
+Return an infinite circular copy of @var{list}.
+The returned list cycles through the elements of @var{list} and repeats
+from the beginning.
+
+@example
+@group
+(-take 5 (-cycle '(1 2 3)))
+    @result{} (1 2 3 1 2)
+@end group
+@group
+(-take 7 (-cycle '(1 "and" 3)))
+    @result{} (1 "and" 3 1 "and" 3 1)
+@end group
+@group
+(-zip (-cycle '(1 2 3)) '(1 2))
+    @result{} ((1 . 1) (2 . 2))
+@end group
+@end example
+@end defun
+
 @node Predicates
 @section Predicates
 
@@ -2765,27 +2808,6 @@ The time complexity is @var{o}(n).
 @end example
 @end defun
 
-@anchor{-repeat}
-@defun -repeat (n x)
-Return a new list of length @var{n} with each element being @var{x}.
-Return @code{nil} if @var{n} is less than 1.
-
-@example
-@group
-(-repeat 3 :a)
-    @result{} (:a :a :a)
-@end group
-@group
-(-repeat 1 :a)
-    @result{} (:a)
-@end group
-@group
-(-repeat 0 :a)
-    @result{} nil
-@end group
-@end example
-@end defun
-
 @anchor{-cons*}
 @defun -cons* (&rest args)
 Make a new list from the elements of @var{args}.
@@ -3029,28 +3051,6 @@ See also: @code{-zip} (@pxref{-zip})
 @end example
 @end defun
 
-@anchor{-cycle}
-@defun -cycle (list)
-Return an infinite circular copy of @var{list}.
-The returned list cycles through the elements of @var{list} and repeats
-from the beginning.
-
-@example
-@group
-(-take 5 (-cycle '(1 2 3)))
-    @result{} (1 2 3 1 2)
-@end group
-@group
-(-take 7 (-cycle '(1 "and" 3)))
-    @result{} (1 "and" 3 1 "and" 3 1)
-@end group
-@group
-(-zip (-cycle '(1 2 3)) '(1 2))
-    @result{} ((1 . 1) (2 . 2))
-@end group
-@end example
-@end defun
-
 @anchor{-pad}
 @defun -pad (fill-value &rest lists)
 Pad each of @var{lists} with @var{fill-value} until they all have equal 
lengths.
diff --git a/dev/examples.el b/dev/examples.el
index 54a8b237bd..33cef8bb58 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -721,7 +721,25 @@ value rather than consuming a list to produce a single 
value."
   (defexamples -unfold
     (-unfold (lambda (x) (unless (= x 0) (cons x (1- x)))) 10) => '(10 9 8 7 6 
5 4 3 2 1)
     (--unfold (when it (cons it (cdr it))) '(1 2 3 4)) => '((1 2 3 4) (2 3 4) 
(3 4) (4))
-    (--unfold (when it (cons it (butlast it))) '(1 2 3 4)) => '((1 2 3 4) (1 2 
3) (1 2) (1))))
+    (--unfold (when it (cons it (butlast it))) '(1 2 3 4)) => '((1 2 3 4) (1 2 
3) (1 2) (1)))
+
+  (defexamples -repeat
+    (-repeat 3 :a) => '(:a :a :a)
+    (-repeat 1 :a) => '(:a)
+    (-repeat 0 :a) => '()
+    (-repeat -1 :a) => ()
+    (-repeat -1 ()) => ()
+    (-repeat 0 ()) => ()
+    (-repeat 1 ()) => '(())
+    (-repeat 2 ()) => '(() ()))
+
+  (defexamples -cycle
+    (-take 5 (-cycle '(1 2 3))) => '(1 2 3 1 2)
+    (-take 7 (-cycle '(1 "and" 3))) => '(1 "and" 3 1 "and" 3 1)
+    (-zip (-cycle '(1 2 3)) '(1 2)) => '((1 . 1) (2 . 2))
+    (-zip-with #'cons (-cycle '(1 2 3)) '(1 2)) => '((1 . 1) (2 . 2))
+    (-map (-partial #'-take 5) (-split-at 5 (-cycle '(1 2 3)))) => '((1 2 3 1 
2) (3 1 2 3 1))
+    (let ((l (list 1))) (eq l (-cycle l))) => nil))
 
 (def-example-group "Predicates"
   "Reductions of one or more lists to a boolean value."
@@ -1409,12 +1427,6 @@ related predicates."
     (-rotate 5 '(1 2 3)) => '(2 3 1)
     (-rotate 6 '(1 2 3)) => '(1 2 3))
 
-  (defexamples -repeat
-    (-repeat 3 :a) => '(:a :a :a)
-    (-repeat 1 :a) => '(:a)
-    (-repeat 0 :a) => nil
-    (-repeat -1 :a) => nil)
-
   (defexamples -cons*
     (-cons* 1 2) => '(1 . 2)
     (-cons* 1 2 3) => '(1 2 . 3)
@@ -1484,14 +1496,6 @@ related predicates."
     (-unzip '((1 2) (3 4) (5 6) (7 8) (9 10))) => '((1 3 5 7 9) (2 4 6 8 10))
     (-unzip '((1 2) (3 4))) => '((1 . 3) (2 . 4)))
 
-  (defexamples -cycle
-    (-take 5 (-cycle '(1 2 3))) => '(1 2 3 1 2)
-    (-take 7 (-cycle '(1 "and" 3))) => '(1 "and" 3 1 "and" 3 1)
-    (-zip (-cycle '(1 2 3)) '(1 2)) => '((1 . 1) (2 . 2))
-    (-zip-with #'cons (-cycle '(1 2 3)) '(1 2)) => '((1 . 1) (2 . 2))
-    (-map (-partial #'-take 5) (-split-at 5 (-cycle '(1 2 3)))) => '((1 2 3 1 
2) (3 1 2 3 1))
-    (let ((l (list 1))) (eq l (-cycle l))) => nil)
-
   (defexamples -pad
     (-pad 0 '()) => '(())
     (-pad 0 '(1 2) '(3 4)) => '((1 2) (3 4))



reply via email to

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