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

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

[elpa] externals/dash d8bcf56 086/316: Add -running-sum and -running-pro


From: ELPA Syncer
Subject: [elpa] externals/dash d8bcf56 086/316: Add -running-sum and -running-product
Date: Mon, 15 Feb 2021 15:57:31 -0500 (EST)

branch: externals/dash
commit d8bcf567ef96dc20011d830b88b8d975e2acb451
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>

    Add -running-sum and -running-product
---
 README.md       | 22 ++++++++++++++++++++++
 dash.el         | 12 ++++++++++++
 dash.texi       | 40 ++++++++++++++++++++++++++++++++++++++++
 dev/examples.el | 10 ++++++++++
 4 files changed, 84 insertions(+)

diff --git a/README.md b/README.md
index 17b9b24..c24960d 100644
--- a/README.md
+++ b/README.md
@@ -137,7 +137,9 @@ Functions reducing lists into single value.
 * [-reduce-r](#-reduce-r-fn-list) `(fn list)`
 * [-count](#-count-pred-list) `(pred list)`
 * [-sum](#-sum-list) `(list)`
+* [-running-sum](#-running-sum-list) `(list)`
 * [-product](#-product-list) `(list)`
+* [-running-product](#-running-product-list) `(list)`
 * [-min](#-min-list) `(list)`
 * [-min-by](#-min-by-comparator-list) `(comparator list)`
 * [-max](#-max-list) `(list)`
@@ -927,6 +929,16 @@ Return the sum of `list`.
 (-sum '(1 2 3 4)) ;; => 10
 ```
 
+#### -running-sum `(list)`
+
+Return a list with running sums of items in `list`.
+
+```el
+(-running-sum '()) ;; => nil
+(-running-sum '(1)) ;; => '(1)
+(-running-sum '(1 2 3 4)) ;; => '(1 3 6 10)
+```
+
 #### -product `(list)`
 
 Return the product of `list`.
@@ -937,6 +949,16 @@ Return the product of `list`.
 (-product '(1 2 3 4)) ;; => 24
 ```
 
+#### -running-product `(list)`
+
+Return a list with running products of items in `list`.
+
+```el
+(-running-product '()) ;; => nil
+(-running-product '(1)) ;; => '(1)
+(-running-product '(1 2 3 4)) ;; => '(1 2 6 24)
+```
+
 #### -min `(list)`
 
 Return the smallest value from `list` of numbers or markers.
diff --git a/dash.el b/dash.el
index d016d00..7e0c75d 100644
--- a/dash.el
+++ b/dash.el
@@ -2189,11 +2189,21 @@ Return nil if N is less than 1."
   (declare (pure t) (side-effect-free t))
   (apply '+ list))
 
+(defun -running-sum (list)
+  "Return a list with running sums of items in LIST."
+  (declare (pure t) (side-effect-free t))
+  (-map '-sum (-inits list)))
+
 (defun -product (list)
   "Return the product of LIST."
   (declare (pure t) (side-effect-free t))
   (apply '* list))
 
+(defun -running-product (list)
+  "Return a list with running products of items in LIST."
+  (declare (pure t) (side-effect-free t))
+  (-map '-product (-inits list)))
+
 (defun -max (list)
   "Return the largest value from LIST of numbers or markers."
   (declare (pure t) (side-effect-free t))
@@ -2651,7 +2661,9 @@ structure such as plist or alist."
                              "-list"
                              "-repeat"
                              "-sum"
+                             "-running-sum"
                              "-product"
+                             "-running-product"
                              "-max"
                              "-min"
                              "-max-by"
diff --git a/dash.texi b/dash.texi
index 6a60f65..ece320c 100644
--- a/dash.texi
+++ b/dash.texi
@@ -1216,6 +1216,26 @@ Return the sum of @var{list}.
 @end example
 @end defun
 
+@anchor{-running-sum}
+@defun -running-sum (list)
+Return a list with running sums of items in @var{list}.
+
+@example
+@group
+(-running-sum '())
+    @result{} nil
+@end group
+@group
+(-running-sum '(1))
+    @result{} '(1)
+@end group
+@group
+(-running-sum '(1 2 3 4))
+    @result{} '(1 3 6 10)
+@end group
+@end example
+@end defun
+
 @anchor{-product}
 @defun -product (list)
 Return the product of @var{list}.
@@ -1236,6 +1256,26 @@ Return the product of @var{list}.
 @end example
 @end defun
 
+@anchor{-running-product}
+@defun -running-product (list)
+Return a list with running products of items in @var{list}.
+
+@example
+@group
+(-running-product '())
+    @result{} nil
+@end group
+@group
+(-running-product '(1))
+    @result{} '(1)
+@end group
+@group
+(-running-product '(1 2 3 4))
+    @result{} '(1 2 6 24)
+@end group
+@end example
+@end defun
+
 @anchor{-min}
 @defun -min (list)
 Return the smallest value from @var{list} of numbers or markers.
diff --git a/dev/examples.el b/dev/examples.el
index 796d933..a560ec3 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -342,11 +342,21 @@ new list."
     (-sum '(1)) => 1
     (-sum '(1 2 3 4)) => 10)
 
+  (defexamples -running-sum
+    (-running-sum '()) => nil
+    (-running-sum '(1)) => '(1)
+    (-running-sum '(1 2 3 4)) => '(1 3 6 10))
+
   (defexamples -product
     (-product '()) => 1
     (-product '(1)) => 1
     (-product '(1 2 3 4)) => 24)
 
+  (defexamples -running-product
+    (-running-product '()) => nil
+    (-running-product '(1)) => '(1)
+    (-running-product '(1 2 3 4)) => '(1 2 6 24))
+
   (defexamples -min
     (-min '(0)) => 0
     (-min '(3 2 1)) => 1



reply via email to

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