From b614dc6b4139035a9c33554831aec4b439955f39 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Tue, 23 Apr 2024 16:17:09 +0300 Subject: [PATCH] lib/lists: init; add `listContainsValue` Helps us validate lists that contain a bunch of values and see if it contains a desired list of values --- lib/default.nix | 1 + lib/lists.nix | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 lib/lists.nix diff --git a/lib/default.nix b/lib/default.nix index 693aff9..eade2e2 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -9,6 +9,7 @@ binds = import ./binds.nix {inherit lib;}; dag = import ./dag.nix {inherit lib;}; languages = import ./languages.nix {inherit lib;}; + lists = import ./lists.nix {inherit lib;}; lua = import ./lua.nix {inherit lib;}; vim = import ./vim.nix; } diff --git a/lib/lists.nix b/lib/lists.nix new file mode 100644 index 0000000..25e85ad --- /dev/null +++ b/lib/lists.nix @@ -0,0 +1,34 @@ +{lib}: let + inherit (lib.lists) elem all; +in { + /* + Checks if all values are present in the list. + + Type: + listContainsValues :: { list :: [a], values :: [a] } -> Bool + + Arguments: + list - A list of elements. + values - A list of values to check for presence in the list. + + Returns: + True if all values are present in the list, otherwise False. + + Example: + ```nix + listContainsValues { list = [1 2 3]; values = [2 3]; } + => True + + listContainsValues { list = [1 2 3]; values = [2 4]; } + => False + ``` + */ + listContainsValues = { + list, + values, + }: let + # Check if all values are present in the list + containsValue = value: elem value list; + in + all containsValue values; +}