diff options
| author | Nicolas Petton | 2015-10-26 21:51:30 +0100 |
|---|---|---|
| committer | Nicolas Petton | 2015-10-26 22:17:41 +0100 |
| commit | 7637849321a5bf3db8213ab23c38131a78e37dc9 (patch) | |
| tree | bfcc8280838d1d04f8910bf60614124f6adeef62 | |
| parent | 5c86118b4ba818ed1fd48258f884f95d98674693 (diff) | |
| download | emacs-7637849321a5bf3db8213ab23c38131a78e37dc9.tar.gz emacs-7637849321a5bf3db8213ab23c38131a78e37dc9.zip | |
* lisp/emacs-lisp/seq.el: Rename all seq argumentss to sequence.
| -rw-r--r-- | lisp/emacs-lisp/seq.el | 306 |
1 files changed, 153 insertions, 153 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index f5189c7dc97..05e53783385 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el | |||
| @@ -63,9 +63,9 @@ | |||
| 63 | "Loop over a sequence. | 63 | "Loop over a sequence. |
| 64 | Similar to `dolist' but can be applied to lists, strings, and vectors. | 64 | Similar to `dolist' but can be applied to lists, strings, and vectors. |
| 65 | 65 | ||
| 66 | Evaluate BODY with VAR bound to each element of SEQ, in turn. | 66 | Evaluate BODY with VAR bound to each element of SEQUENCE, in turn. |
| 67 | 67 | ||
| 68 | \(fn (VAR SEQ) BODY...)" | 68 | \(fn (VAR SEQUENCE) BODY...)" |
| 69 | (declare (indent 1) (debug ((symbolp form &optional form) body))) | 69 | (declare (indent 1) (debug ((symbolp form &optional form) body))) |
| 70 | `(seq-do (lambda (,(car spec)) | 70 | `(seq-do (lambda (,(car spec)) |
| 71 | ,@body) | 71 | ,@body) |
| @@ -82,284 +82,284 @@ PATTERNS are given, and the match does not fail." | |||
| 82 | `(and (pred seq-p) | 82 | `(and (pred seq-p) |
| 83 | ,@(seq--make-pcase-bindings patterns))) | 83 | ,@(seq--make-pcase-bindings patterns))) |
| 84 | 84 | ||
| 85 | (defmacro seq-let (args seq &rest body) | 85 | (defmacro seq-let (args sequence &rest body) |
| 86 | "Bind the variables in ARGS to the elements of SEQ then evaluate BODY. | 86 | "Bind the variables in ARGS to the elements of SEQUENCE then evaluate BODY. |
| 87 | 87 | ||
| 88 | ARGS can also include the `&rest' marker followed by a variable | 88 | ARGS can also include the `&rest' marker followed by a variable |
| 89 | name to be bound to the rest of SEQ." | 89 | name to be bound to the rest of SEQUENCE." |
| 90 | (declare (indent 2) (debug t)) | 90 | (declare (indent 2) (debug t)) |
| 91 | `(pcase-let ((,(seq--make-pcase-patterns args) ,seq)) | 91 | `(pcase-let ((,(seq--make-pcase-patterns args) ,sequence)) |
| 92 | ,@body)) | 92 | ,@body)) |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | ;;; Basic seq functions that have to be implemented by new seq types | 95 | ;;; Basic seq functions that have to be implemented by new sequence types |
| 96 | (cl-defgeneric seq-elt (seq n) | 96 | (cl-defgeneric seq-elt (sequence n) |
| 97 | "Return the element of SEQ at index N." | 97 | "Return the element of SEQUENCE at index N." |
| 98 | (elt seq n)) | 98 | (elt sequence n)) |
| 99 | 99 | ||
| 100 | ;; Default gv setters for `seq-elt'. | 100 | ;; Default gv setters for `seq-elt'. |
| 101 | ;; It can be a good idea for new sequence implementations to provide a | 101 | ;; It can be a good idea for new sequence implementations to provide a |
| 102 | ;; "gv-setter" for `seq-elt'. | 102 | ;; "gv-setter" for `seq-elt'. |
| 103 | (cl-defmethod (setf seq-elt) (store (seq array) n) | 103 | (cl-defmethod (setf seq-elt) (store (sequence array) n) |
| 104 | (aset seq n store)) | 104 | (aset sequence n store)) |
| 105 | 105 | ||
| 106 | (cl-defmethod (setf seq-elt) (store (seq cons) n) | 106 | (cl-defmethod (setf seq-elt) (store (sequence cons) n) |
| 107 | (setcar (nthcdr n seq) store)) | 107 | (setcar (nthcdr n sequence) store)) |
| 108 | 108 | ||
| 109 | (cl-defgeneric seq-length (seq) | 109 | (cl-defgeneric seq-length (sequence) |
| 110 | "Return the length of the sequence SEQ." | 110 | "Return the length of SEQUENCE." |
| 111 | (length seq)) | 111 | (length sequence)) |
| 112 | 112 | ||
| 113 | (cl-defgeneric seq-do (function seq) | 113 | (cl-defgeneric seq-do (function sequence) |
| 114 | "Apply FUNCTION to each element of SEQ, presumably for side effects. | 114 | "Apply FUNCTION to each element of SEQUENCE, presumably for side effects. |
| 115 | Return SEQ." | 115 | Return SEQUENCE." |
| 116 | (mapc function seq)) | 116 | (mapc function sequence)) |
| 117 | 117 | ||
| 118 | (defalias 'seq-each #'seq-do) | 118 | (defalias 'seq-each #'seq-do) |
| 119 | 119 | ||
| 120 | (cl-defgeneric seq-p (seq) | 120 | (cl-defgeneric seq-p (sequence) |
| 121 | "Return non-nil if SEQ is a sequence, nil otherwise." | 121 | "Return non-nil if SEQUENCE is a sequence, nil otherwise." |
| 122 | (sequencep seq)) | 122 | (sequencep sequence)) |
| 123 | 123 | ||
| 124 | (cl-defgeneric seq-copy (seq) | 124 | (cl-defgeneric seq-copy (sequence) |
| 125 | "Return a shallow copy of SEQ." | 125 | "Return a shallow copy of SEQUENCE." |
| 126 | (copy-sequence seq)) | 126 | (copy-sequence sequence)) |
| 127 | 127 | ||
| 128 | (cl-defgeneric seq-subseq (seq start &optional end) | 128 | (cl-defgeneric seq-subseq (sequence start &optional end) |
| 129 | "Return the subsequence of SEQ from START to END. | 129 | "Return the subsequence of SEQUENCE from START to END. |
| 130 | If END is omitted, it defaults to the length of the sequence. | 130 | If END is omitted, it defaults to the length of the sequence. |
| 131 | If START or END is negative, it counts from the end. | 131 | If START or END is negative, it counts from the end. |
| 132 | Signal an error if START or END are outside of the sequence (i.e | 132 | Signal an error if START or END are outside of the sequence (i.e |
| 133 | too large if positive or too small if negative)." | 133 | too large if positive or too small if negative)." |
| 134 | (cl-subseq seq start end)) | 134 | (cl-subseq sequence start end)) |
| 135 | 135 | ||
| 136 | 136 | ||
| 137 | (cl-defgeneric seq-map (function seq) | 137 | (cl-defgeneric seq-map (function sequence) |
| 138 | "Return the result of applying FUNCTION to each element of SEQ." | 138 | "Return the result of applying FUNCTION to each element of SEQUENCE." |
| 139 | (let (result) | 139 | (let (result) |
| 140 | (seq-do (lambda (elt) | 140 | (seq-do (lambda (elt) |
| 141 | (push (funcall function elt) result)) | 141 | (push (funcall function elt) result)) |
| 142 | seq) | 142 | sequence) |
| 143 | (nreverse result))) | 143 | (nreverse result))) |
| 144 | 144 | ||
| 145 | ;; faster implementation for sequences (sequencep) | 145 | ;; faster implementation for sequences (sequencep) |
| 146 | (cl-defmethod seq-map (function (seq sequence)) | 146 | (cl-defmethod seq-map (function (sequence sequence)) |
| 147 | (mapcar function seq)) | 147 | (mapcar function sequence)) |
| 148 | 148 | ||
| 149 | (cl-defgeneric seq-drop (seq n) | 149 | (cl-defgeneric seq-drop (sequence n) |
| 150 | "Return a subsequence of SEQ without its first N elements. | 150 | "Return a subsequence of SEQUENCE without its first N elements. |
| 151 | The result is a sequence of the same type as SEQ. | 151 | The result is a sequence of the same type as SEQUENCE. |
| 152 | 152 | ||
| 153 | If N is a negative integer or zero, SEQ is returned." | 153 | If N is a negative integer or zero, SEQUENCE is returned." |
| 154 | (if (<= n 0) | 154 | (if (<= n 0) |
| 155 | seq | 155 | sequence |
| 156 | (let ((length (seq-length seq))) | 156 | (let ((length (seq-length sequence))) |
| 157 | (seq-subseq seq (min n length) length)))) | 157 | (seq-subseq sequence (min n length) length)))) |
| 158 | 158 | ||
| 159 | (cl-defgeneric seq-take (seq n) | 159 | (cl-defgeneric seq-take (sequence n) |
| 160 | "Return a subsequence of SEQ with its first N elements. | 160 | "Return a subsequence of SEQUENCE with its first N elements. |
| 161 | The result is a sequence of the same type as SEQ. | 161 | The result is a sequence of the same type as SEQUENCE. |
| 162 | 162 | ||
| 163 | If N is a negative integer or zero, an empty sequence is | 163 | If N is a negative integer or zero, an empty sequence is |
| 164 | returned." | 164 | returned." |
| 165 | (seq-subseq seq 0 (min (max n 0) (seq-length seq)))) | 165 | (seq-subseq sequence 0 (min (max n 0) (seq-length sequence)))) |
| 166 | 166 | ||
| 167 | (cl-defgeneric seq-drop-while (pred seq) | 167 | (cl-defgeneric seq-drop-while (pred sequence) |
| 168 | "Return a sequence from the first element for which (PRED element) is nil in SEQ. | 168 | "Return a sequence from the first element for which (PRED element) is nil in SEQUENCE. |
| 169 | The result is a sequence of the same type as SEQ." | 169 | The result is a sequence of the same type as SEQUENCE." |
| 170 | (seq-drop seq (seq--count-successive pred seq))) | 170 | (seq-drop sequence (seq--count-successive pred sequence))) |
| 171 | 171 | ||
| 172 | (cl-defgeneric seq-take-while (pred seq) | 172 | (cl-defgeneric seq-take-while (pred sequence) |
| 173 | "Return the successive elements for which (PRED element) is non-nil in SEQ. | 173 | "Return the successive elements for which (PRED element) is non-nil in SEQUENCE. |
| 174 | The result is a sequence of the same type as SEQ." | 174 | The result is a sequence of the same type as SEQUENCE." |
| 175 | (seq-take seq (seq--count-successive pred seq))) | 175 | (seq-take sequence (seq--count-successive pred sequence))) |
| 176 | 176 | ||
| 177 | (cl-defgeneric seq-empty-p (seq) | 177 | (cl-defgeneric seq-empty-p (sequence) |
| 178 | "Return non-nil if the sequence SEQ is empty, nil otherwise." | 178 | "Return non-nil if the SEQUENCE is empty, nil otherwise." |
| 179 | (= 0 (seq-length seq))) | 179 | (= 0 (seq-length sequence))) |
| 180 | 180 | ||
| 181 | (cl-defgeneric seq-sort (pred seq) | 181 | (cl-defgeneric seq-sort (pred sequence) |
| 182 | "Return a sorted sequence comparing using PRED the elements of SEQ. | 182 | "Return a sorted sequence comparing using PRED the elements of SEQUENCE. |
| 183 | The result is a sequence of the same type as SEQ." | 183 | The result is a sequence of the same type as SEQUENCE." |
| 184 | (let ((result (seq-sort pred (append seq nil)))) | 184 | (let ((result (seq-sort pred (append sequence nil)))) |
| 185 | (seq-into result (type-of seq)))) | 185 | (seq-into result (type-of sequence)))) |
| 186 | 186 | ||
| 187 | (cl-defmethod seq-sort (pred (list list)) | 187 | (cl-defmethod seq-sort (pred (list list)) |
| 188 | (sort (seq-copy list) pred)) | 188 | (sort (seq-copy list) pred)) |
| 189 | 189 | ||
| 190 | (cl-defgeneric seq-reverse (seq) | 190 | (cl-defgeneric seq-reverse (sequence) |
| 191 | "Return the reversed shallow copy of SEQ." | 191 | "Return the reversed shallow copy of SEQUENCE." |
| 192 | (let ((result '())) | 192 | (let ((result '())) |
| 193 | (seq-map (lambda (elt) | 193 | (seq-map (lambda (elt) |
| 194 | (push elt result)) | 194 | (push elt result)) |
| 195 | seq) | 195 | sequence) |
| 196 | (seq-into result (type-of seq)))) | 196 | (seq-into result (type-of sequence)))) |
| 197 | 197 | ||
| 198 | ;; faster implementation for sequences (sequencep) | 198 | ;; faster implementation for sequences (sequencep) |
| 199 | (cl-defmethod seq-reverse ((seq sequence)) | 199 | (cl-defmethod seq-reverse ((sequence sequence)) |
| 200 | (reverse seq)) | 200 | (reverse sequence)) |
| 201 | 201 | ||
| 202 | (cl-defgeneric seq-concatenate (type &rest seqs) | 202 | (cl-defgeneric seq-concatenate (type &rest sequences) |
| 203 | "Concatenate, into a sequence of type TYPE, the sequences SEQS. | 203 | "Concatenate, into a sequence of type TYPE, the sequences SEQUENCES. |
| 204 | TYPE must be one of following symbols: vector, string or list. | 204 | TYPE must be one of following symbols: vector, string or list. |
| 205 | 205 | ||
| 206 | \n(fn TYPE SEQUENCE...)" | 206 | \n(fn TYPE SEQUENCE...)" |
| 207 | (apply #'cl-concatenate type (seq-map #'seq-into-sequence seqs))) | 207 | (apply #'cl-concatenate type (seq-map #'seq-into-sequence sequences))) |
| 208 | 208 | ||
| 209 | (cl-defgeneric seq-into-sequence (seq) | 209 | (cl-defgeneric seq-into-sequence (sequence) |
| 210 | "Convert SEQ into a sequence. | 210 | "Convert SEQUENCE into a sequence. |
| 211 | 211 | ||
| 212 | The default implementation is to signal an error if SEQ is not a | 212 | The default implementation is to signal an error if SEQUENCE is not a |
| 213 | sequence, specific functions should be implemented for new types | 213 | sequence, specific functions should be implemented for new types |
| 214 | of seq." | 214 | of sequence." |
| 215 | (unless (sequencep seq) | 215 | (unless (sequencep sequence) |
| 216 | (error "Cannot convert %S into a sequence" seq)) | 216 | (error "Cannot convert %S into a sequence" sequence)) |
| 217 | seq) | 217 | sequence) |
| 218 | 218 | ||
| 219 | (cl-defgeneric seq-into (seq type) | 219 | (cl-defgeneric seq-into (sequence type) |
| 220 | "Convert the sequence SEQ into a sequence of type TYPE. | 220 | "Convert SEQUENCE into a sequence of type TYPE. |
| 221 | TYPE can be one of the following symbols: vector, string or list." | 221 | TYPE can be one of the following symbols: vector, string or list." |
| 222 | (pcase type | 222 | (pcase type |
| 223 | (`vector (vconcat seq)) | 223 | (`vector (vconcat sequence)) |
| 224 | (`string (concat seq)) | 224 | (`string (concat sequence)) |
| 225 | (`list (append seq nil)) | 225 | (`list (append sequence nil)) |
| 226 | (_ (error "Not a sequence type name: %S" type)))) | 226 | (_ (error "Not a sequence type name: %S" type)))) |
| 227 | 227 | ||
| 228 | (cl-defgeneric seq-filter (pred seq) | 228 | (cl-defgeneric seq-filter (pred sequence) |
| 229 | "Return a list of all the elements for which (PRED element) is non-nil in SEQ." | 229 | "Return a list of all the elements for which (PRED element) is non-nil in SEQUENCE." |
| 230 | (let ((exclude (make-symbol "exclude"))) | 230 | (let ((exclude (make-symbol "exclude"))) |
| 231 | (delq exclude (seq-map (lambda (elt) | 231 | (delq exclude (seq-map (lambda (elt) |
| 232 | (if (funcall pred elt) | 232 | (if (funcall pred elt) |
| 233 | elt | 233 | elt |
| 234 | exclude)) | 234 | exclude)) |
| 235 | seq)))) | 235 | sequence)))) |
| 236 | 236 | ||
| 237 | (cl-defgeneric seq-remove (pred seq) | 237 | (cl-defgeneric seq-remove (pred sequence) |
| 238 | "Return a list of all the elements for which (PRED element) is nil in SEQ." | 238 | "Return a list of all the elements for which (PRED element) is nil in SEQUENCE." |
| 239 | (seq-filter (lambda (elt) (not (funcall pred elt))) | 239 | (seq-filter (lambda (elt) (not (funcall pred elt))) |
| 240 | seq)) | 240 | sequence)) |
| 241 | 241 | ||
| 242 | (cl-defgeneric seq-reduce (function seq initial-value) | 242 | (cl-defgeneric seq-reduce (function sequence initial-value) |
| 243 | "Reduce the function FUNCTION across SEQ, starting with INITIAL-VALUE. | 243 | "Reduce the function FUNCTION across SEQUENCE, starting with INITIAL-VALUE. |
| 244 | 244 | ||
| 245 | Return the result of calling FUNCTION with INITIAL-VALUE and the | 245 | Return the result of calling FUNCTION with INITIAL-VALUE and the |
| 246 | first element of SEQ, then calling FUNCTION with that result and | 246 | first element of SEQUENCE, then calling FUNCTION with that result and |
| 247 | the second element of SEQ, then with that result and the third | 247 | the second element of SEQUENCE, then with that result and the third |
| 248 | element of SEQ, etc. | 248 | element of SEQUENCE, etc. |
| 249 | 249 | ||
| 250 | If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called." | 250 | If SEQUENCE is empty, return INITIAL-VALUE and FUNCTION is not called." |
| 251 | (if (seq-empty-p seq) | 251 | (if (seq-empty-p sequence) |
| 252 | initial-value | 252 | initial-value |
| 253 | (let ((acc initial-value)) | 253 | (let ((acc initial-value)) |
| 254 | (seq-doseq (elt seq) | 254 | (seq-doseq (elt sequence) |
| 255 | (setq acc (funcall function acc elt))) | 255 | (setq acc (funcall function acc elt))) |
| 256 | acc))) | 256 | acc))) |
| 257 | 257 | ||
| 258 | (cl-defgeneric seq-every-p (pred seq) | 258 | (cl-defgeneric seq-every-p (pred sequence) |
| 259 | "Return non-nil if (PRED element) is non-nil for all elements of the sequence SEQ." | 259 | "Return non-nil if (PRED element) is non-nil for all elements of SEQUENCE." |
| 260 | (catch 'seq--break | 260 | (catch 'seq--break |
| 261 | (seq-doseq (elt seq) | 261 | (seq-doseq (elt sequence) |
| 262 | (or (funcall pred elt) | 262 | (or (funcall pred elt) |
| 263 | (throw 'seq--break nil))) | 263 | (throw 'seq--break nil))) |
| 264 | t)) | 264 | t)) |
| 265 | 265 | ||
| 266 | (cl-defgeneric seq-some (pred seq) | 266 | (cl-defgeneric seq-some (pred sequence) |
| 267 | "Return the first value for which if (PRED element) is non-nil for in SEQ." | 267 | "Return the first value for which if (PRED element) is non-nil for in SEQUENCE." |
| 268 | (catch 'seq--break | 268 | (catch 'seq--break |
| 269 | (seq-doseq (elt seq) | 269 | (seq-doseq (elt sequence) |
| 270 | (let ((result (funcall pred elt))) | 270 | (let ((result (funcall pred elt))) |
| 271 | (when result | 271 | (when result |
| 272 | (throw 'seq--break result)))) | 272 | (throw 'seq--break result)))) |
| 273 | nil)) | 273 | nil)) |
| 274 | 274 | ||
| 275 | (cl-defgeneric seq-find (pred seq &optional default) | 275 | (cl-defgeneric seq-find (pred sequence &optional default) |
| 276 | "Return the first element for which (PRED element) is non-nil in SEQ. | 276 | "Return the first element for which (PRED element) is non-nil in SEQUENCE. |
| 277 | If no element is found, return DEFAULT. | 277 | If no element is found, return DEFAULT. |
| 278 | 278 | ||
| 279 | Note that `seq-find' has an ambiguity if the found element is | 279 | Note that `seq-find' has an ambiguity if the found element is |
| 280 | identical to DEFAULT, as it cannot be known if an element was | 280 | identical to DEFAULT, as it cannot be known if an element was |
| 281 | found or not." | 281 | found or not." |
| 282 | (catch 'seq--break | 282 | (catch 'seq--break |
| 283 | (seq-doseq (elt seq) | 283 | (seq-doseq (elt sequence) |
| 284 | (when (funcall pred elt) | 284 | (when (funcall pred elt) |
| 285 | (throw 'seq--break elt))) | 285 | (throw 'seq--break elt))) |
| 286 | default)) | 286 | default)) |
| 287 | 287 | ||
| 288 | (cl-defgeneric seq-count (pred seq) | 288 | (cl-defgeneric seq-count (pred sequence) |
| 289 | "Return the number of elements for which (PRED element) is non-nil in SEQ." | 289 | "Return the number of elements for which (PRED element) is non-nil in SEQUENCE." |
| 290 | (let ((count 0)) | 290 | (let ((count 0)) |
| 291 | (seq-doseq (elt seq) | 291 | (seq-doseq (elt sequence) |
| 292 | (when (funcall pred elt) | 292 | (when (funcall pred elt) |
| 293 | (setq count (+ 1 count)))) | 293 | (setq count (+ 1 count)))) |
| 294 | count)) | 294 | count)) |
| 295 | 295 | ||
| 296 | (cl-defgeneric seq-contains (seq elt &optional testfn) | 296 | (cl-defgeneric seq-contains (sequence elt &optional testfn) |
| 297 | "Return the first element in SEQ that is equal to ELT. | 297 | "Return the first element in SEQUENCE that is equal to ELT. |
| 298 | Equality is defined by TESTFN if non-nil or by `equal' if nil." | 298 | Equality is defined by TESTFN if non-nil or by `equal' if nil." |
| 299 | (seq-some (lambda (e) | 299 | (seq-some (lambda (e) |
| 300 | (funcall (or testfn #'equal) elt e)) | 300 | (funcall (or testfn #'equal) elt e)) |
| 301 | seq)) | 301 | sequence)) |
| 302 | 302 | ||
| 303 | (cl-defgeneric seq-position (seq elt &optional testfn) | 303 | (cl-defgeneric seq-position (sequence elt &optional testfn) |
| 304 | "Return the index of the first element in SEQ that is equal to ELT. | 304 | "Return the index of the first element in SEQUENCE that is equal to ELT. |
| 305 | Equality is defined by TESTFN if non-nil or by `equal' if nil." | 305 | Equality is defined by TESTFN if non-nil or by `equal' if nil." |
| 306 | (let ((index 0)) | 306 | (let ((index 0)) |
| 307 | (catch 'seq--break | 307 | (catch 'seq--break |
| 308 | (seq-doseq (e seq) | 308 | (seq-doseq (e sequence) |
| 309 | (when (funcall (or testfn #'equal) e elt) | 309 | (when (funcall (or testfn #'equal) e elt) |
| 310 | (throw 'seq--break index)) | 310 | (throw 'seq--break index)) |
| 311 | (setq index (1+ index))) | 311 | (setq index (1+ index))) |
| 312 | nil))) | 312 | nil))) |
| 313 | 313 | ||
| 314 | (cl-defgeneric seq-uniq (seq &optional testfn) | 314 | (cl-defgeneric seq-uniq (sequence &optional testfn) |
| 315 | "Return a list of the elements of SEQ with duplicates removed. | 315 | "Return a list of the elements of SEQUENCE with duplicates removed. |
| 316 | TESTFN is used to compare elements, or `equal' if TESTFN is nil." | 316 | TESTFN is used to compare elements, or `equal' if TESTFN is nil." |
| 317 | (let ((result '())) | 317 | (let ((result '())) |
| 318 | (seq-doseq (elt seq) | 318 | (seq-doseq (elt sequence) |
| 319 | (unless (seq-contains result elt testfn) | 319 | (unless (seq-contains result elt testfn) |
| 320 | (setq result (cons elt result)))) | 320 | (setq result (cons elt result)))) |
| 321 | (nreverse result))) | 321 | (nreverse result))) |
| 322 | 322 | ||
| 323 | (cl-defgeneric seq-mapcat (function seq &optional type) | 323 | (cl-defgeneric seq-mapcat (function sequence &optional type) |
| 324 | "Concatenate the result of applying FUNCTION to each element of SEQ. | 324 | "Concatenate the result of applying FUNCTION to each element of SEQUENCE. |
| 325 | The result is a sequence of type TYPE, or a list if TYPE is nil." | 325 | The result is a sequence of type TYPE, or a list if TYPE is nil." |
| 326 | (apply #'seq-concatenate (or type 'list) | 326 | (apply #'seq-concatenate (or type 'list) |
| 327 | (seq-map function seq))) | 327 | (seq-map function sequence))) |
| 328 | 328 | ||
| 329 | (cl-defgeneric seq-partition (seq n) | 329 | (cl-defgeneric seq-partition (sequence n) |
| 330 | "Return a list of the elements of SEQ grouped into sub-sequences of length N. | 330 | "Return a list of the elements of SEQUENCE grouped into sub-sequences of length N. |
| 331 | The last sequence may contain less than N elements. If N is a | 331 | The last sequence may contain less than N elements. If N is a |
| 332 | negative integer or 0, nil is returned." | 332 | negative integer or 0, nil is returned." |
| 333 | (unless (< n 1) | 333 | (unless (< n 1) |
| 334 | (let ((result '())) | 334 | (let ((result '())) |
| 335 | (while (not (seq-empty-p seq)) | 335 | (while (not (seq-empty-p sequence)) |
| 336 | (push (seq-take seq n) result) | 336 | (push (seq-take sequence n) result) |
| 337 | (setq seq (seq-drop seq n))) | 337 | (setq sequence (seq-drop sequence n))) |
| 338 | (nreverse result)))) | 338 | (nreverse result)))) |
| 339 | 339 | ||
| 340 | (cl-defgeneric seq-intersection (seq1 seq2 &optional testfn) | 340 | (cl-defgeneric seq-intersection (sequence1 sequence2 &optional testfn) |
| 341 | "Return a list of the elements that appear in both SEQ1 and SEQ2. | 341 | "Return a list of the elements that appear in both SEQUENCE1 and SEQUENCE2. |
| 342 | Equality is defined by TESTFN if non-nil or by `equal' if nil." | 342 | Equality is defined by TESTFN if non-nil or by `equal' if nil." |
| 343 | (seq-reduce (lambda (acc elt) | 343 | (seq-reduce (lambda (acc elt) |
| 344 | (if (seq-contains seq2 elt testfn) | 344 | (if (seq-contains sequence2 elt testfn) |
| 345 | (cons elt acc) | 345 | (cons elt acc) |
| 346 | acc)) | 346 | acc)) |
| 347 | (seq-reverse seq1) | 347 | (seq-reverse sequence1) |
| 348 | '())) | 348 | '())) |
| 349 | 349 | ||
| 350 | (cl-defgeneric seq-difference (seq1 seq2 &optional testfn) | 350 | (cl-defgeneric seq-difference (sequence1 sequence2 &optional testfn) |
| 351 | "Return a list of the elements that appear in SEQ1 but not in SEQ2. | 351 | "Return a list of the elements that appear in SEQUENCE1 but not in SEQUENCE2. |
| 352 | Equality is defined by TESTFN if non-nil or by `equal' if nil." | 352 | Equality is defined by TESTFN if non-nil or by `equal' if nil." |
| 353 | (seq-reduce (lambda (acc elt) | 353 | (seq-reduce (lambda (acc elt) |
| 354 | (if (not (seq-contains seq2 elt testfn)) | 354 | (if (not (seq-contains sequence2 elt testfn)) |
| 355 | (cons elt acc) | 355 | (cons elt acc) |
| 356 | acc)) | 356 | acc)) |
| 357 | (seq-reverse seq1) | 357 | (seq-reverse sequence1) |
| 358 | '())) | 358 | '())) |
| 359 | 359 | ||
| 360 | (cl-defgeneric seq-group-by (function seq) | 360 | (cl-defgeneric seq-group-by (function sequence) |
| 361 | "Apply FUNCTION to each element of SEQ. | 361 | "Apply FUNCTION to each element of SEQUENCE. |
| 362 | Separate the elements of SEQ into an alist using the results as | 362 | Separate the elements of SEQUENCE into an alist using the results as |
| 363 | keys. Keys are compared using `equal'." | 363 | keys. Keys are compared using `equal'." |
| 364 | (seq-reduce | 364 | (seq-reduce |
| 365 | (lambda (acc elt) | 365 | (lambda (acc elt) |
| @@ -369,25 +369,25 @@ keys. Keys are compared using `equal'." | |||
| 369 | (setcdr cell (push elt (cdr cell))) | 369 | (setcdr cell (push elt (cdr cell))) |
| 370 | (push (list key elt) acc)) | 370 | (push (list key elt) acc)) |
| 371 | acc)) | 371 | acc)) |
| 372 | (seq-reverse seq) | 372 | (seq-reverse sequence) |
| 373 | nil)) | 373 | nil)) |
| 374 | 374 | ||
| 375 | (cl-defgeneric seq-min (seq) | 375 | (cl-defgeneric seq-min (sequence) |
| 376 | "Return the smallest element of SEQ. | 376 | "Return the smallest element of SEQUENCE. |
| 377 | SEQ must be a sequence of numbers or markers." | 377 | SEQUENCE must be a sequence of numbers or markers." |
| 378 | (apply #'min (seq-into seq 'list))) | 378 | (apply #'min (seq-into sequence 'list))) |
| 379 | 379 | ||
| 380 | (cl-defgeneric seq-max (seq) | 380 | (cl-defgeneric seq-max (sequence) |
| 381 | "Return the largest element of SEQ. | 381 | "Return the largest element of SEQUENCE. |
| 382 | SEQ must be a sequence of numbers or markers." | 382 | SEQUENCE must be a sequence of numbers or markers." |
| 383 | (apply #'max (seq-into seq 'list))) | 383 | (apply #'max (seq-into sequence 'list))) |
| 384 | 384 | ||
| 385 | (defun seq--count-successive (pred seq) | 385 | (defun seq--count-successive (pred sequence) |
| 386 | "Return the number of successive elements for which (PRED element) is non-nil in SEQ." | 386 | "Return the number of successive elements for which (PRED element) is non-nil in SEQUENCE." |
| 387 | (let ((n 0) | 387 | (let ((n 0) |
| 388 | (len (seq-length seq))) | 388 | (len (seq-length sequence))) |
| 389 | (while (and (< n len) | 389 | (while (and (< n len) |
| 390 | (funcall pred (seq-elt seq n))) | 390 | (funcall pred (seq-elt sequence n))) |
| 391 | (setq n (+ 1 n))) | 391 | (setq n (+ 1 n))) |
| 392 | n)) | 392 | n)) |
| 393 | 393 | ||
| @@ -419,10 +419,10 @@ SEQ must be a sequence of numbers or markers." | |||
| 419 | args))) | 419 | args))) |
| 420 | 420 | ||
| 421 | ;; TODO: make public? | 421 | ;; TODO: make public? |
| 422 | (defun seq--elt-safe (seq n) | 422 | (defun seq--elt-safe (sequence n) |
| 423 | "Return element of SEQ at the index N. | 423 | "Return element of SEQUENCE at the index N. |
| 424 | If no element is found, return nil." | 424 | If no element is found, return nil." |
| 425 | (ignore-errors (seq-elt seq n))) | 425 | (ignore-errors (seq-elt sequence n))) |
| 426 | 426 | ||
| 427 | 427 | ||
| 428 | ;;; Optimized implementations for lists | 428 | ;;; Optimized implementations for lists |