From e31840e78be8ebc1378209d6084c74a893c27d9f Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Sat, 3 Aug 2024 10:58:42 -0600 Subject: [PATCH] feat: use capital letter for public export It is much less verbose that a `pub_` prefix. --- default.nix | 21 ++++++++------------- dev/mod.nix | 4 ++-- std/file/mod.nix | 2 +- std/mod.nix | 9 +++++---- std/path/mod.nix | 2 +- std/set/mod.nix | 4 ++-- std/string/mod.nix | 10 ++++++++++ std/string/toLowerCase.nix | 6 ++++++ test/bld/buzz/fuzz/mod.nix | 2 +- test/bld/buzz/mod.nix | 2 +- test/bld/mod.nix | 12 ++++++------ 11 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 std/string/mod.nix create mode 100644 std/string/toLowerCase.nix diff --git a/default.nix b/default.nix index ffe5bdc..992cb0c 100644 --- a/default.nix +++ b/default.nix @@ -3,9 +3,14 @@ let filterMap = scopedImport { std = builtins; } ./std/set/filterMap.nix; parse = scopedImport { std = builtins; } ./std/file/parse.nix; strToPath = scopedImport { std = builtins; } ./std/path/strToPath.nix; + toLowerCase = scopedImport rec { + std = builtins; + mod = scopedImport { inherit std mod; } ./std/string/mod.nix; + } ./std/string/toLowerCase.nix; cond = import ./std/set/cond.nix; compose = import ./.; + lowerKeys = filterMap (k: v: { ${toLowerCase k} = v; }); filterMod = builtins.filterSource ( path: type: let @@ -26,19 +31,11 @@ let "atom" (baseNameOf dir) ]; - stripPub = - s: - let - s' = builtins.match "^pub_(.*)" s; - in - if s' == null then s else builtins.head s'; - - rmPub = filterMap (k: v: { ${stripPub k} = v; }); filterPub = filterMap ( k: v: let - s = stripPub k; + s = toLowerCase k; in if s == k then null else { ${s} = v; } ); @@ -61,9 +58,7 @@ let { inherit std; atom = atom'; - mod = builtins.removeAttrs self [ "mod" ] // { - outPath = filterMod dir; - }; + mod = lowerKeys (builtins.removeAttrs self [ "mod" ] // { outPath = filterMod dir; }); } // cond { _if = pre != null; @@ -80,7 +75,7 @@ let if type == "directory" then { ${name} = f ( - (rmPub self) + (lowerKeys self) // cond { _if = pre != null; inherit pre; diff --git a/dev/mod.nix b/dev/mod.nix index 6050947..9262f19 100644 --- a/dev/mod.nix +++ b/dev/mod.nix @@ -1,4 +1,4 @@ { - pub_pkgs = mod.pkgs; - pub_shell = mod.shell; + Pkgs = mod.pkgs; + Shell = mod.shell; } diff --git a/std/file/mod.nix b/std/file/mod.nix index 251abd3..9080af5 100644 --- a/std/file/mod.nix +++ b/std/file/mod.nix @@ -1 +1 @@ -{ pub_parse = mod.parse; } +{ Parse = mod.parse; } diff --git a/std/mod.nix b/std/mod.nix index 2427783..23c06c1 100644 --- a/std/mod.nix +++ b/std/mod.nix @@ -1,6 +1,7 @@ { - pub_fix = mod.fix; - pub_file = mod.file; - pub_set = mod.set; - pub_path = mod.path; + Fix = mod.fix; + File = mod.file; + Set = mod.set; + Path = mod.path; + String = mod.string; } diff --git a/std/path/mod.nix b/std/path/mod.nix index 9ded5fd..0cdacaa 100644 --- a/std/path/mod.nix +++ b/std/path/mod.nix @@ -1 +1 @@ -{ pub_strToPath = mod.strToPath; } +{ StrToPath = mod.strToPath; } diff --git a/std/set/mod.nix b/std/set/mod.nix index 9c58ddf..c4e1638 100644 --- a/std/set/mod.nix +++ b/std/set/mod.nix @@ -1,4 +1,4 @@ { - pub_cond = mod.cond; - pub_filterMap = mod.filterMap; + Cond = mod.cond; + FilterMap = mod.filterMap; } diff --git a/std/string/mod.nix b/std/string/mod.nix new file mode 100644 index 0000000..1ff3263 --- /dev/null +++ b/std/string/mod.nix @@ -0,0 +1,10 @@ +{ + upperChars = mod.stringToChars "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + lowerChars = mod.stringToChars "abcdefghijklmnopqrstuvwxyz"; + + stringToChars = s: std.genList (p: std.substring p 1 s) (std.stringLength s); + + ToLower = std.replaceStrings mod.upperChars mod.lowerChars; + + ToLowerCase = mod.toLowerCase; +} diff --git a/std/string/toLowerCase.nix b/std/string/toLowerCase.nix new file mode 100644 index 0000000..5c2c006 --- /dev/null +++ b/std/string/toLowerCase.nix @@ -0,0 +1,6 @@ +s: +let + head = std.substring 0 1 s; + tail = std.substring 1 (-1) s; +in +"${mod.toLower or mod.ToLower head}${tail}" diff --git a/test/bld/buzz/fuzz/mod.nix b/test/bld/buzz/fuzz/mod.nix index dcb0a2c..e2f6bc0 100644 --- a/test/bld/buzz/fuzz/mod.nix +++ b/test/bld/buzz/fuzz/mod.nix @@ -1,5 +1,5 @@ { foo = 1; - pub_bar = pre.bar + 2; + Bar = pre.bar + 2; baz = mod.bar + 4; } diff --git a/test/bld/buzz/mod.nix b/test/bld/buzz/mod.nix index b81c4bc..1bf22f8 100644 --- a/test/bld/buzz/mod.nix +++ b/test/bld/buzz/mod.nix @@ -2,5 +2,5 @@ foo = 1; bar = pre.foo + 2; baz = mod.bar + 4; - pub_fuzz = mod.fuzz; + Fuzz = mod.fuzz; } diff --git a/test/bld/mod.nix b/test/bld/mod.nix index 99ed272..9451116 100644 --- a/test/bld/mod.nix +++ b/test/bld/mod.nix @@ -1,10 +1,10 @@ { - pub_foo = 1; + Foo = 1; bar = atom.foo + 2; baz = mod.bar + 4; - pub_f = std.set.filterMap; - pub_file = builtins.readFile "${mod}/bum"; - pub_buzz = mod.buzz; - pub_next = ./next; # should be a non-existant path: /nix/store/next - pub_bar = mod.bar; + F = std.set.filterMap; + File = builtins.readFile "${mod}/bum"; + Buzz = mod.buzz; + Next = ./next; # should be a non-existant path: /nix/store/next + Bar = mod.bar; }