]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/seq/seq-24.el
Add patterns for character properties
[gnu-emacs-elpa] / packages / seq / seq-24.el
index f34fd11897c80e3b07c9810d2c2b79771fc4f573..3b08855421dd207ed17e5504579e514d7e98e94f 100644 (file)
@@ -1,6 +1,6 @@
 ;;; seq-24.el --- seq.el implementation for Emacs 24.x -*- lexical-binding: t -*-
 
-;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
+;; Copyright (C) 2014-2016 Free Software Foundation, Inc.
 
 ;; Author: Nicolas Petton <nicolas@petton.fr>
 ;; Keywords: sequences
@@ -202,6 +202,16 @@ The result is a sequence of the same type as SEQUENCE."
     (let ((result (seq-sort predicate (append sequence nil))))
       (seq-into result (type-of sequence)))))
 
+(defun seq-sort-by (function pred sequence)
+  "Sort SEQUENCE using PRED as a comparison function.
+Elements of SEQUENCE are transformed by FUNCTION before being
+sorted.  FUNCTION must be a function of one argument."
+  (seq-sort (lambda (a b)
+              (funcall pred
+                       (funcall function a)
+                       (funcall function b)))
+            sequence))
+
 (defun seq-contains (sequence elt &optional testfn)
   "Return the first element in SEQUENCE that equals to ELT.
 Equality is defined by TESTFN if non-nil or by `equal' if nil."
@@ -260,7 +270,7 @@ TYPE must be one of following symbols: vector, string or list.
     (`vector (apply #'vconcat seqs))
     (`string (apply #'concat seqs))
     (`list (apply #'append (append seqs '(nil))))
-    (t (error "Not a sequence type name: %S" type))))
+    (_ (error "Not a sequence type name: %S" type))))
 
 (defun seq-mapcat (function sequence &optional type)
   "Concatenate the result of applying FUNCTION to each element of SEQUENCE.
@@ -349,7 +359,7 @@ TYPE can be one of the following symbols: vector, string or list."
     (`vector (vconcat sequence))
     (`string (concat sequence))
     (`list (append sequence nil))
-    (t (error "Not a sequence type name: %S" type))))
+    (_ (error "Not a sequence type name: %S" type))))
 
 (defun seq-min (sequence)
   "Return the smallest element of SEQUENCE.
@@ -422,7 +432,7 @@ BINDINGS."
                           (seq-drop ,sequence ,index))
                         bindings)
                   (setq rest-marker t)))
-          (t
+          (_
            (push `(,name (seq--elt-safe ,sequence ,index)) bindings))))
       (setq index (1+ index)))
     bindings))