branch: externals/dash commit 55d8cc9294437ffd718acfeeb8b143da0637a125 Author: Matus Goljer <matus.gol...@gmail.com> Commit: Matus Goljer <matus.gol...@gmail.com>
Running sum and product can only be computed from non-empty lists --- dash.el | 16 ++++++++++++---- dev/examples.el | 8 ++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dash.el b/dash.el index f40dad1..4136851 100644 --- a/dash.el +++ b/dash.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." diff --git a/dev/examples.el b/dev/examples.el index d629cba..8e7b5dd 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -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