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

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

[elpa] externals/dash 7e41bed 192/426: Merge pull request #35 from rejee


From: Phillip Lord
Subject: [elpa] externals/dash 7e41bed 192/426: Merge pull request #35 from rejeep/sum-and-product
Date: Tue, 04 Aug 2015 19:37:39 +0000

branch: externals/dash
commit 7e41bed5330d09b1ccab5083b15e9c3a5573ac3f
Merge: 50659cc 12291f3
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Merge pull request #35 from rejeep/sum-and-product
    
    Add -sum and -product functions
---
 README.md       |   22 ++++++++++++++++++++++
 dash.el         |   10 ++++++++++
 dev/examples.el |   10 ++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md
index 0fc1f8c..03dcf34 100644
--- a/README.md
+++ b/README.md
@@ -75,6 +75,8 @@ Or you can just dump `dash.el` in your load path somewhere.
 * [-if-let*](#-if-let-vars-vals-then-optional-else) `(vars-vals then &optional 
else)`
 * [!cons](#-cons-car-cdr) `(car cdr)`
 * [!cdr](#-cdr-list) `(list)`
+* [-sum](#-sum-list) `(list)`
+* [-product](#-product-list) `(list)`
 
 There are also anaphoric versions of these functions where that makes sense,
 prefixed with two dashes instead of one.
@@ -825,6 +827,26 @@ Destructive: Sets `list` to the cdr of `list`.
 (let ((l '(3 5))) (!cdr l) l) ;; => '(5)
 ```
 
+### -sum `(list)`
+
+Return the sum of `list`.
+
+```cl
+(-sum '()) ;; => 0
+(-sum '(1)) ;; => 1
+(-sum '(1 2 3)) ;; => 6
+```
+
+### -product `(list)`
+
+Return the product of `list`.
+
+```cl
+(-product '()) ;; => 1
+(-product '(1)) ;; => 1
+(-product '(1 2 3)) ;; => 6
+```
+
 
 ## Contribute
 
diff --git a/dash.el b/dash.el
index 025ec11..7f41af6 100644
--- a/dash.el
+++ b/dash.el
@@ -872,6 +872,14 @@ Returns nil if N is less than 1."
     (--dotimes n (!cons x ret))
     ret))
 
+(defun -sum (list)
+  "Return the sum of LIST."
+  (apply '+ list))
+
+(defun -product (list)
+  "Return the product of LIST."
+  (apply '* list))
+
 (eval-after-load "lisp-mode"
   '(progn
      (let ((new-keywords '(
@@ -974,6 +982,8 @@ Returns nil if N is less than 1."
                            "-contains-p"
                            "-repeat"
                            "-cons*"
+                           "-sum"
+                           "-product"
                            ))
            (special-variables '(
                                 "it"
diff --git a/dev/examples.el b/dev/examples.el
index 48561ba..2730583 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -336,3 +336,13 @@
 (defexamples !cdr
   (let ((l '(3))) (!cdr l) l) => '()
   (let ((l '(3 5))) (!cdr l) l) => '(5))
+
+(defexamples -sum
+  (-sum '()) => 0
+  (-sum '(1)) => 1
+  (-sum '(1 2 3)) => 6)
+
+(defexamples -product
+  (-product '()) => 1
+  (-product '(1)) => 1
+  (-product '(1 2 3)) => 6)



reply via email to

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