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

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

[elpa] externals/dash 6a57833 054/316: Add -iota (#207)


From: ELPA Syncer
Subject: [elpa] externals/dash 6a57833 054/316: Add -iota (#207)
Date: Mon, 15 Feb 2021 15:57:24 -0500 (EST)

branch: externals/dash
commit 6a578338b6666844e6df34876c775974f6ec7dab
Author: Mark Oteiza <mvoteiza@udel.edu>
Commit: Mark Oteiza <mvoteiza@udel.edu>

    Add -iota (#207)
---
 dash.el         | 17 +++++++++++++++++
 dev/examples.el |  4 ++++
 2 files changed, 21 insertions(+)

diff --git a/dash.el b/dash.el
index 078175c..afa5fad 100644
--- a/dash.el
+++ b/dash.el
@@ -2154,6 +2154,23 @@ N is the length of the returned list."
         (push (funcall fun (car r)) r))
       (nreverse r))))
 
+(defun -iota (count &optional start step)
+  "Return a list containing COUNT numbers.
+Starts from START and adds STEP each time.  The default START is
+zero, the default STEP is 1.
+This function takes its name from the corresponding primitive in
+the APL language."
+  (if (or (not (integerp count)) (< count 0))
+      (signal 'wrong-type-argument count))
+  (if (and step (zerop step)) (make-list count start)
+    (let ((res '())
+          (x (or start 0))
+          (dx (or step 1)))
+      (while (<= 0 (setq count (1- count)))
+        (push x res)
+        (setq x (+ x dx)))
+      (nreverse res))))
+
 (defun -fix (fn list)
   "Compute the (least) fixpoint of FN with initial input LIST.
 
diff --git a/dev/examples.el b/dev/examples.el
index 092e57e..3e0ca88 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -614,6 +614,10 @@ new list."
     (-interleave '(1 2 3) '("a" "b")) => '(1 "a" 2 "b")
     (-interleave '(1 2 3) '("a" "b" "c" "d")) => '(1 "a" 2 "b" 3 "c"))
 
+  (defexamples -iota
+    (-iota 6) => '(0 1 2 3 4 5)
+    (-iota 4 2.5 -2) => '(2.5 0.5 -1.5 -3.5))
+
   (defexamples -zip-with
     (-zip-with '+ '(1 2 3) '(4 5 6)) => '(5 7 9)
     (-zip-with 'cons '(1 2 3) '(4 5 6)) => '((1 . 4) (2 . 5) (3 . 6))



reply via email to

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