Reduce usage of cl-* functions

* calibre-cli.el (calibre-cli--get-authors):
  (calibre-cli--get-tags):
  (calibre-cli--get-formats):
* calibre-core.el (calibre--get-filter-items):
  (calibre-library--filter):
* calibre-search.el (calibre-search--operation):

  Replace cl-* functions with equivalent seq-* functions.
This commit is contained in:
Kjartan Oli Agustsson 2023-10-29 22:17:13 +00:00
parent dae6a54a38
commit 4f980e2161
Signed by: kjartanoli
GPG Key ID: D7572FE3605EE6B0
3 changed files with 42 additions and 31 deletions

View File

@ -132,9 +132,11 @@ AUTHORS should be a comma separated string."
(defun calibre-cli--get-authors ()
"Return a list of the authors in the active library."
(cl-remove-duplicates
(cl-reduce #'cl-union (mapcar (lambda (b)
(calibre-cli--parse-authors (alist-get 'authors b)))
(calibre-cli--list "authors")))
(seq-reduce #'seq-union
(mapcar (lambda (b)
(calibre-cli--parse-authors (alist-get 'authors b)))
(calibre-cli--list "authors"))
'())
:test #'string=))
(defun calibre-cli--get-publishers ()
@ -155,17 +157,19 @@ AUTHORS should be a comma separated string."
(defun calibre-cli--get-tags ()
"Return a list of the tags in the active library."
(cl-remove-duplicates
(cl-reduce #'cl-union (mapcar (lambda (b)
(alist-get 'tags b))
(calibre-cli--list "tags")))
:test #'string=))
(seq-reduce #'seq-union
(mapcar (lambda (b)
(alist-get 'tags b))
(calibre-cli--list "tags"))
'()))
(defun calibre-cli--get-formats ()
"Return a list of the file formats stored in the active library."
(cl-reduce #'cl-union (mapcar (lambda (b)
(calibre-cli--parse-formats (alist-get 'formats b)))
(calibre-cli--list "formats"))))
(seq-reduce #'seq-union
(mapcar (lambda (b)
(calibre-cli--parse-formats (alist-get 'formats b)))
(calibre-cli--list "formats"))
'()))
(provide 'calibre-cli)
;;; calibre-cli.el ends here

View File

@ -208,12 +208,15 @@ BOOK is a `calibre-book'."
"Return the id's of books matching FILTER."
(if (calibre-composite-filter-p filter)
(seq-let (op filters) filter
(cl-reduce (if (eq op '+)
#'cl-union
#'cl-intersection)
(mapcar (lambda (f)
(seq-reduce (if (eq op '+)
#'seq-union
#'seq-intersection)
(mapcar (lambda (f)
(calibre--get-filter-items (vconcat `[,op] f)))
filters)))
filters)
(if (eq op '+)
'()
(calibre--books))))
(seq-let (_ field value) filter
(cl-case field
(title (calibre-core--interface get-title-books value))
@ -227,23 +230,25 @@ BOOK is a `calibre-book'."
"Return those books in BOOKS that match FILTERS.
FILTERS should be a list of vectors, for the exact contents see
`calibre-virtual-libraries'."
(let* ((include (cl-remove-if-not (lambda (f) (eq (elt f 0) '+)) filters))
(exclude (cl-remove-if-not (lambda (f) (eq (elt f 0) '-)) filters))
(let* ((include (seq-filter (lambda (f) (eq (elt f 0) '+)) filters))
(exclude (seq-filter (lambda (f) (eq (elt f 0) '-)) filters))
(include-ids (when include
(cl-reduce #'cl-intersection
(mapcar #'calibre--get-filter-items include))))
(seq-reduce #'seq-intersection
(mapcar #'calibre--get-filter-items include)
(mapcar #'calibre-book-id calibre--books))))
(exclude-ids (when exclude
(cl-reduce #'cl-union
(mapcar #'calibre--get-filter-items exclude)))))
(cl-remove-if (lambda (b)
(seq-find (lambda (id)
(= id (calibre-book-id b)))
exclude-ids))
(seq-reduce #'seq-union
(mapcar #'calibre--get-filter-items exclude)
'()))))
(seq-filter (lambda (b)
(not (seq-find (lambda (id)
(= id (calibre-book-id b)))
exclude-ids)))
(if include-ids
(cl-remove-if-not (lambda (b)
(seq-find (lambda (id)
(= id (calibre-book-id b)))
include-ids))
(seq-filter (lambda (b)
(seq-find (lambda (id)
(= id (calibre-book-id b)))
include-ids))
books)
(if include
nil

View File

@ -55,7 +55,9 @@ will not be appended to the calibre-db--get-FIELD function's name."
(defun calibre-search--operation (args)
"Return the appropriate symbol for a filter operation.
ARGS is the argument list of a transient command."
(if (cl-find "--exclude" args :test #'string=) '- '+))
(if (seq-contains-p args "--exclude")
'-
'+))
(defmacro calibre-library--search-function (field)
"Create a function adding a filter for FIELD."