@@ -138,25 +138,36 @@ let
138138
139139 callable =
140140 let
141- __config = {
141+ initial = {
142142 # Accumulated configuration
143143 api = { } ;
144144 mapf = ( i : i ) ;
145145 filterf = _ : true ;
146146 paths = [ ] ;
147147
148+ # config is our state (initial at first). this functor allows it
149+ # to work as if it was a function, taking an update function
150+ # that will return a new state. for example:
151+ # in mergeAttrs: `config (c: c // x)` will merge x into new config.
148152 __functor =
149- self : f :
153+ config : update :
150154 let
151- __config = ( f self ) ;
152- boundAPI = builtins . mapAttrs ( _ : g : g ( self f ) ) __config . api ;
153- accAttr = attrName : acc : self ( c : mapAttr ( f c ) attrName acc ) ;
154- mergeAttrs = attrs : self ( c : ( f c ) // attrs ) ;
155+ # updated is another config
156+ updated = update config ;
157+
158+ # current is the result of this functor.
159+ # it is not a config, but an import-tree object containing a __config.
160+ current = config update ;
161+ boundAPI = builtins . mapAttrs ( _ : g : g current ) updated . api ;
162+
163+ # these two helpers are used to **append** aggregated configs.
164+ accAttr = attrName : acc : config ( c : mapAttr ( update c ) attrName acc ) ;
165+ mergeAttrs = attrs : config ( c : ( update c ) // attrs ) ;
155166 in
156167 boundAPI
157168 // {
158- inherit __config ;
159- __functor = functor ;
169+ __config = updated ;
170+ __functor = functor ; # user-facing callable
160171
161172 # Configuration updates (accumulating)
162173 filter = filterf : accAttr "filterf" ( and filterf ) ;
@@ -174,17 +185,17 @@ let
174185 leafs = mergeAttrs { pipef = ( i : i ) ; } ;
175186
176187 # Applies empty (for already path-configured trees)
177- result = ( self f ) [ ] ;
188+ result = current [ ] ;
178189
179190 # Return a list of all filtered files.
180- files = ( self f ) . leafs . result ;
191+ files = current . leafs . result ;
181192
182193 # returns the original empty state
183194 new = callable ;
184195 } ;
185196 } ;
186197 in
187- __config ( c : c ) ;
198+ initial ( config : config ) ;
188199
189200in
190201callable
0 commit comments