packages: Recognize the '.Z' extension.
[jackhill/guix/guix.git] / emacs / guix-entry.el
1 ;;; guix-entry.el --- 'Entry' type -*- lexical-binding: t -*-
2
3 ;; Copyright © 2015 Alex Kost <alezost@gmail.com>
4
5 ;; This file is part of GNU Guix.
6
7 ;; GNU Guix is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; GNU Guix is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;; This file provides an API for 'entry' type which is just an alist of
23 ;; KEY/VALUE pairs (KEY should be a symbol) with the required 'id' KEY.
24
25 ;;; Code:
26
27 (require 'cl-lib)
28 (require 'guix-utils)
29
30 (defalias 'guix-entry-value #'guix-assq-value)
31
32 (defun guix-entry-id (entry)
33 "Return ENTRY ID."
34 (guix-entry-value entry 'id))
35
36 (defun guix-entry-by-id (id entries)
37 "Return an entry from ENTRIES by its ID."
38 (cl-find-if (lambda (entry)
39 (equal (guix-entry-id entry) id))
40 entries))
41
42 (defun guix-entries-by-ids (ids entries)
43 "Return entries with IDS (a list of identifiers) from ENTRIES."
44 (cl-remove-if-not (lambda (entry)
45 (member (guix-entry-id entry) ids))
46 entries))
47
48 (defun guix-replace-entry (id new-entry entries)
49 "Replace an entry with ID from ENTRIES by NEW-ENTRY.
50 Return a list of entries with the replaced entry."
51 (cl-substitute-if new-entry
52 (lambda (entry)
53 (equal id (guix-entry-id entry)))
54 entries
55 :count 1))
56
57 (provide 'guix-entry)
58
59 ;;; guix-entry.el ends here