fake.modules transposition for aspect-oriented Dendritic Nix. with cross-aspect dependencies. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/
dendrix.oeiuwq.com/Dendritic.html
dendritic
nix
aspect
oriented
1# Generic 2-level attribute set transposition
2# Swaps parent/child levels: { a.b = 1; } → { b.a = 1; }
3# Parameterized via emit function for custom value handling
4
5{
6 lib,
7 # emit: Customization function for each item during transpose
8 # Signature: { child, parent, value } → [{ parent, child, value }]
9 # Default: lib.singleton (identity transformation)
10 emit ? lib.singleton,
11}:
12let
13 # Create transposition metadata by calling emit
14 transposeItem =
15 child: parent: value:
16 emit { inherit child parent value; };
17
18 # Fold accumulator: rebuilds transposed structure
19 accTransposed =
20 acc: item:
21 acc
22 // {
23 ${item.parent} = (acc.${item.parent} or { }) // {
24 ${item.child} = item.value;
25 };
26 };
27
28 # Process all children of a parent
29 transposeItems = parent: lib.mapAttrsToList (transposeItem parent);
30
31 # Flatten input into transposition items
32 deconstruct = lib.mapAttrsToList transposeItems;
33
34 # Fold items back into swapped structure
35 reconstruct = lib.foldl accTransposed { };
36
37 # Main transpose: deconstruct → flatten → reconstruct
38 transpose =
39 attrs:
40 lib.pipe attrs [
41 deconstruct
42 lib.flatten
43 reconstruct
44 ];
45in
46transpose