emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master b1047c3 1/2: Add seq-min and seq-max


From: Nicolas Petton
Subject: [Emacs-diffs] master b1047c3 1/2: Add seq-min and seq-max
Date: Tue, 30 Jun 2015 16:40:32 +0000

branch: master
commit b1047c3b422f5280a9de6c56b1ba77e5dbc185ee
Author: Nicolas Petton <address@hidden>
Commit: Nicolas Petton <address@hidden>

    Add seq-min and seq-max
    
    Bump version number.
    
    * lisp/emacs-lisp/seq.el (seq-min, seq-max): New functions.
    * test/automated/seq-tests.el: Add tests for seq-min and seq-max.
---
 lisp/emacs-lisp/seq.el      |   12 +++++++++++-
 test/automated/seq-tests.el |    5 +++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 2d20de6..68d40b9 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
 
 ;; Author: Nicolas Petton <address@hidden>
 ;; Keywords: sequences
-;; Version: 1.7
+;; Version: 1.8
 ;; Package: seq
 
 ;; Maintainer: address@hidden
@@ -325,6 +325,16 @@ TYPE can be one of the following symbols: vector, string 
or list."
     (`list (append seq nil))
     (_ (error "Not a sequence type name: %S" type))))
 
+(defun seq-min (seq)
+  "Return the smallest element of SEQ.
+SEQ must be a sequence of numbers or markers."
+  (apply #'min (seq-into seq 'list)))
+
+(defun seq-max (seq)
+    "Return the largest element of SEQ.
+SEQ must be a sequence of numbers or markers."
+  (apply #'max (seq-into seq 'list)))
+
 (defun seq--drop-list (list n)
   "Return a list from LIST without its first N elements.
 This is an optimization for lists in `seq-drop'."
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index ab46eb8..3643ce5 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -297,5 +297,10 @@ Evaluate BODY for each created sequence.
       (should (null b))
       (should (null c)))))
 
+(ert-deftest test-seq-min-max ()
+  (with-test-sequences (seq '(4 5 3 2 0 4))
+    (should (= (seq-min seq) 0))
+    (should (= (seq-max seq) 5))))
+
 (provide 'seq-tests)
 ;;; seq-tests.el ends here



reply via email to

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