start detangling lib

This commit is contained in:
Jeff Hykin 2024-05-25 12:14:33 -04:00
parent 9cb4ed1ffc
commit a4c9fde3e9
3 changed files with 197 additions and 167 deletions

View file

@ -4,32 +4,38 @@
* for new functions in `./tests.nix`.
*/
let
loadStatic = (folder:
{
setup = builtins.fromTOML ( builtins.readFile "${folder}/static/setup.toml" );
meta = builtins.fromTOML ( builtins.readFile "${folder}/static/meta.toml" );
}
);
static = loadStatic ../.;
untangledLib = {
foundation = import ./detangled/1_foundation.nix;
fixedPoints = import ./detangled/2_fixed-points.nix;
in
let
static = foundation.loadStatic ../.;
untangledBase = {
# constants
sourceTypes = static.setup.sourceTypes;
licenses = static.setup.licenses;
maintainers = static.setup.maintainers;
teams = static.setup.teams;
builtins = builtins;# just to be overridable
loadStatic = loadStatic;
# just to be overridable
builtins = builtins;
# top level helpers
loadStatic = foundation.loadStatic;
foldr = foundation.foldr;
# namespaces
fixedPoints = fixedPoints;
};
inherit (import ./fixed-points.nix { inherit lib; }) makeExtensible;
lib = makeExtensible (self: let
#
# legacy lib
#
lib = fixedPoints.makeExtensible (self: let
callLibs = file: import file { lib = self; };
in untangledLib // {
in untangledBase // {
fixedPoints = fixedPoints;
# often used, or depending on very little
trivial = callLibs ./trivial.nix;
fixedPoints = callLibs ./fixed-points.nix;
# datatypes
attrsets = callLibs ./attrsets.nix;

View file

@ -0,0 +1,22 @@
#
# foundation contains functions that only depend on builtins
#
{
loadStatic = (folder:
{
setup = builtins.fromTOML ( builtins.readFile "${folder}/static/setup.toml" );
meta = builtins.fromTOML ( builtins.readFile "${folder}/static/meta.toml" );
}
);
foldr = (
op: nul: list:
let
len = builtins.length list;
fold' = n:
if n == len
then nul
else op (builtins.elemAt list n) (fold' (n + 1));
in
fold' 0
);
}

View file

@ -1,4 +1,6 @@
{ foldr }:
let # internal lib dependencies
foundation = import ./1_foundation.nix;
in
let
/*
`fix f` computes the fixed point of the given function `f`. In other words, the return value is `x` in `x = f x`.
@ -274,7 +276,7 @@
```
*/
composeManyExtensions =
foldr (x: y: composeExtensions x y) (final: prev: {});
foundation.foldr (x: y: composeExtensions x y) (final: prev: {});
/*
Same as `makeExtensible` but the name of the extending attribute is