about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authoradisbladis <adisbladis@gmail.com>2023-12-11 16:36:03 +1300
committeradisbladis <adisbladis@gmail.com>2023-12-11 16:36:29 +1300
commitad647985cf40f0970dac341f5677afafa96edeea (patch)
tree22d68752f4fec5346ed97f632ac73dcdf4e2d565 /lib
parenteec92ca9df6ac423377275170caf58878076f798 (diff)
downloadnixlib-ad647985cf40f0970dac341f5677afafa96edeea.tar
nixlib-ad647985cf40f0970dac341f5677afafa96edeea.tar.gz
nixlib-ad647985cf40f0970dac341f5677afafa96edeea.tar.bz2
nixlib-ad647985cf40f0970dac341f5677afafa96edeea.tar.lz
nixlib-ad647985cf40f0970dac341f5677afafa96edeea.tar.xz
nixlib-ad647985cf40f0970dac341f5677afafa96edeea.tar.zst
nixlib-ad647985cf40f0970dac341f5677afafa96edeea.zip
lib.toHexString: Statically compute hexDigits attrset
Diffstat (limited to 'lib')
-rw-r--r--lib/trivial.nix30
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix
index caff77190fde..5092b68dfe75 100644
--- a/lib/trivial.nix
+++ b/lib/trivial.nix
@@ -510,22 +510,20 @@ rec {
 
      toHexString 250 => "FA"
   */
-  toHexString = i:
-    let
-      toHexDigit = d:
-        if d < 10
-        then toString d
-        else
-          {
-            "10" = "A";
-            "11" = "B";
-            "12" = "C";
-            "13" = "D";
-            "14" = "E";
-            "15" = "F";
-          }.${toString d};
-    in
-      lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
+  toHexString = let
+    hexDigits = {
+      "10" = "A";
+      "11" = "B";
+      "12" = "C";
+      "13" = "D";
+      "14" = "E";
+      "15" = "F";
+    };
+    toHexDigit = d:
+      if d < 10
+      then toString d
+      else hexDigits.${toString d};
+  in i: lib.concatMapStrings toHexDigit (toBaseDigits 16 i);
 
   /* `toBaseDigits base i` converts the positive integer i to a list of its
      digits in the given base. For example: