Merge pull request #207 from holomorph/iota

master
Basil L. Contovounesios 5 years ago
commit 82489971fd
No known key found for this signature in database
GPG Key ID: 205AB54A5D5D8CFF
  1. 17
      dash.el
  2. 5
      dev/examples.el

@ -2699,6 +2699,23 @@ The items for the comparator form are exposed as \"it\" and \"other\"."
(declare (debug (form form)))
`(-min-by (lambda (it other) ,form) ,list))
(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."
(when (not (natnump count))
(signal 'wrong-type-argument (list #'natnump count)))
(or start (setq start 0))
(or step (setq step 1))
(if (zerop step) (make-list count start)
(let (result)
(while (<= 0 (setq count (1- count)))
(push start result)
(setq start (+ start step)))
(nreverse result))))
(defun -fix (fn list)
"Compute the (least) fixpoint of FN with initial input LIST.

@ -879,6 +879,11 @@ value rather than consuming a list to produce a single value."
(-interleave '(1 2 3) '("a" "b" "c" "d")) => '(1 "a" 2 "b" 3 "c")
(-interleave) => nil)
(defexamples -iota
(-iota 6) => '(0 1 2 3 4 5)
(-iota 4 2.5 -2) => '(2.5 0.5 -1.5 -3.5)
(-iota -1) !!> wrong-type-argument)
(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))

Loading…
Cancel
Save