From 219dd073ff32f15e77f367831c5e1eef208f9123 Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Sun, 20 Jul 2025 13:00:43 -0500 Subject: [PATCH] Getting very simple functions first. --- lib/functions/buildLocationList.nix | 1 - lib/functions/location.nix | 9 +++++++++ test/test-buildLocationList.nix | 7 ------- test/test-location.nix | 11 +++++++++++ 4 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 lib/functions/buildLocationList.nix create mode 100644 lib/functions/location.nix delete mode 100644 test/test-buildLocationList.nix create mode 100644 test/test-location.nix diff --git a/lib/functions/buildLocationList.nix b/lib/functions/buildLocationList.nix deleted file mode 100644 index 012706c..0000000 --- a/lib/functions/buildLocationList.nix +++ /dev/null @@ -1 +0,0 @@ -locations: builtins.attrNames locations diff --git a/lib/functions/location.nix b/lib/functions/location.nix new file mode 100644 index 0000000..0bd8db1 --- /dev/null +++ b/lib/functions/location.nix @@ -0,0 +1,9 @@ +{ data, lib }: + +let + mkLocationsList = locations: builtins.attrNames locations; + mkLocationIndex = data: location: lib.lists.findFirstIndex (x: x == location) null (mkLocationsList data); +in +{ + inherit mkLocationsList mkLocationIndex; +} diff --git a/test/test-buildLocationList.nix b/test/test-buildLocationList.nix deleted file mode 100644 index 855d45c..0000000 --- a/test/test-buildLocationList.nix +++ /dev/null @@ -1,7 +0,0 @@ -let - buildLocationList = import ../lib/functions/buildLocationList.nix; - sampleData = import ./meta.nix; -in -{ - result = buildLocationList sampleData.locations; -} diff --git a/test/test-location.nix b/test/test-location.nix new file mode 100644 index 0000000..1fd8bda --- /dev/null +++ b/test/test-location.nix @@ -0,0 +1,11 @@ +let + nixpkgs = import { }; + sampleData = import ./meta.nix; + locationLib = import ../lib/functions/location.nix { + data = sampleData; + lib = nixpkgs.lib; + }; +in +{ + result = locationLib.mkLocationIndex sampleData.locations "home"; +}