···138138139139 callable =
140140 let
141141- __config = {
141141+ initial = {
142142 # Accumulated configuration
143143 api = { };
144144 mapf = (i: i);
145145 filterf = _: true;
146146 paths = [ ];
147147148148+ # config is our state (initial at first). this functor allows it
149149+ # to work as if it was a function, taking an update function
150150+ # that will return a new state. for example:
151151+ # in mergeAttrs: `config (c: c // x)` will merge x into new config.
148152 __functor =
149149- self: f:
153153+ config: update:
150154 let
151151- __config = (f self);
152152- boundAPI = builtins.mapAttrs (_: g: g (self f)) __config.api;
153153- accAttr = attrName: acc: self (c: mapAttr (f c) attrName acc);
154154- mergeAttrs = attrs: self (c: (f c) // attrs);
155155+ # updated is another config
156156+ updated = update config;
157157+158158+ # current is the result of this functor.
159159+ # it is not a config, but an import-tree object containing a __config.
160160+ current = config update;
161161+ boundAPI = builtins.mapAttrs (_: g: g current) updated.api;
162162+163163+ # these two helpers are used to **append** aggregated configs.
164164+ accAttr = attrName: acc: config (c: mapAttr (update c) attrName acc);
165165+ mergeAttrs = attrs: config (c: (update c) // attrs);
155166 in
156167 boundAPI
157168 // {
158158- inherit __config;
159159- __functor = functor;
169169+ __config = updated;
170170+ __functor = functor; # user-facing callable
160171161172 # Configuration updates (accumulating)
162173 filter = filterf: accAttr "filterf" (and filterf);
···174185 leafs = mergeAttrs { pipef = (i: i); };
175186176187 # Applies empty (for already path-configured trees)
177177- result = (self f) [ ];
188188+ result = current [ ];
178189179190 # Return a list of all filtered files.
180180- files = (self f).leafs.result;
191191+ files = current.leafs.result;
181192182193 # returns the original empty state
183194 new = callable;
184195 };
185196 };
186197 in
187187- __config (c: c);
198198+ initial (config: config);
188199189200in
190201callable