Running sum and product can only be computed from non-empty lists

master
Matus Goljer 8 years ago
parent eb1231eca4
commit 55d8cc9294
  1. 16
      dash.el
  2. 8
      dev/examples.el

@ -2222,9 +2222,13 @@ Return nil if N is less than 1."
(apply '+ list))
(defun -running-sum (list)
"Return a list with running sums of items in LIST."
"Return a list with running sums of items in LIST.
LIST must be non-empty."
(declare (pure t) (side-effect-free t))
(-map '-sum (-inits list)))
(unless (consp list)
(error "LIST must be non-empty"))
(-reductions '+ list))
(defun -product (list)
"Return the product of LIST."
@ -2232,9 +2236,13 @@ Return nil if N is less than 1."
(apply '* list))
(defun -running-product (list)
"Return a list with running products of items in LIST."
"Return a list with running products of items in LIST.
LIST must be non-empty."
(declare (pure t) (side-effect-free t))
(-map '-product (-inits list)))
(unless (consp list)
(error "LIST must be non-empty"))
(-reductions '* list))
(defun -max (list)
"Return the largest value from LIST of numbers or markers."

@ -363,9 +363,9 @@ new list."
(-sum '(1 2 3 4)) => 10)
(defexamples -running-sum
(-running-sum '()) => nil
(-running-sum '(1 2 3 4)) => '(1 3 6 10)
(-running-sum '(1)) => '(1)
(-running-sum '(1 2 3 4)) => '(1 3 6 10))
(-running-sum '()) !!> error)
(defexamples -product
(-product '()) => 1
@ -373,9 +373,9 @@ new list."
(-product '(1 2 3 4)) => 24)
(defexamples -running-product
(-running-product '()) => nil
(-running-product '(1 2 3 4)) => '(1 2 6 24)
(-running-product '(1)) => '(1)
(-running-product '(1 2 3 4)) => '(1 2 6 24))
(-running-product '()) !!> error)
(defexamples -min
(-min '(0)) => 0

Loading…
Cancel
Save