Skip to content

Commit

Permalink
feat: use capital letter for public export
Browse files Browse the repository at this point in the history
It is much less verbose that a `pub_` prefix.
  • Loading branch information
nrdxp committed Aug 3, 2024
1 parent 3ab2c2e commit e31840e
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 31 deletions.
21 changes: 8 additions & 13 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; }
);
Expand All @@ -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;
Expand All @@ -80,7 +75,7 @@ let
if type == "directory" then
{
${name} = f (
(rmPub self)
(lowerKeys self)
// cond {
_if = pre != null;
inherit pre;
Expand Down
4 changes: 2 additions & 2 deletions dev/mod.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
pub_pkgs = mod.pkgs;
pub_shell = mod.shell;
Pkgs = mod.pkgs;
Shell = mod.shell;
}
2 changes: 1 addition & 1 deletion std/file/mod.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ pub_parse = mod.parse; }
{ Parse = mod.parse; }
9 changes: 5 additions & 4 deletions std/mod.nix
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion std/path/mod.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ pub_strToPath = mod.strToPath; }
{ StrToPath = mod.strToPath; }
4 changes: 2 additions & 2 deletions std/set/mod.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
pub_cond = mod.cond;
pub_filterMap = mod.filterMap;
Cond = mod.cond;
FilterMap = mod.filterMap;
}
10 changes: 10 additions & 0 deletions std/string/mod.nix
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 6 additions & 0 deletions std/string/toLowerCase.nix
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 1 addition & 1 deletion test/bld/buzz/fuzz/mod.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
foo = 1;
pub_bar = pre.bar + 2;
Bar = pre.bar + 2;
baz = mod.bar + 4;
}
2 changes: 1 addition & 1 deletion test/bld/buzz/mod.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
foo = 1;
bar = pre.foo + 2;
baz = mod.bar + 4;
pub_fuzz = mod.fuzz;
Fuzz = mod.fuzz;
}
12 changes: 6 additions & 6 deletions test/bld/mod.nix
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit e31840e

Please sign in to comment.