lib.fixedPoints.extends: Refactor implementation and document arguments

- Better names:
  - self -> final
  - super -> prev
  - rattrs -> f
  - f -> overlay
- Add documentation to the function arguments
- Add some spacing
This commit is contained in:
Silvan Mosberger 2023-08-10 00:18:08 +02:00
parent 327f1c2d09
commit 149a793c07

View file

@ -129,7 +129,20 @@ rec {
fix (extends (final: prev: { c = final.a + final.b; }) f)
=> { a = 1; b = 3; c = 4; }
*/
extends = f: rattrs: self: let super = rattrs self; in super // f self super;
extends =
# The overlay to apply to the fixed-point function
overlay:
# The fixed-point function
f:
# Wrap with parenthesis to prevent nixdoc from rendering the `final` argument in the documentation
# The result should be thought of as a function, the argument of that function is not an argument to `extends` itself
(
final:
let
prev = f final;
in
prev // overlay final prev
);
/*
Compose two extending functions of the type expected by 'extends'