about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2023-08-10 00:10:31 +0200
committerSilvan Mosberger <contact@infinisil.com>2023-08-10 00:26:06 +0200
commit327f1c2d09fec31ae38665911bd6383c10498dad (patch)
tree8eaf5427b0a72321b2667a95079d988b37539176 /lib
parent8585568d7d9f895b928d297f2df7b0d73c069d7c (diff)
downloadnixlib-327f1c2d09fec31ae38665911bd6383c10498dad.tar
nixlib-327f1c2d09fec31ae38665911bd6383c10498dad.tar.gz
nixlib-327f1c2d09fec31ae38665911bd6383c10498dad.tar.bz2
nixlib-327f1c2d09fec31ae38665911bd6383c10498dad.tar.lz
nixlib-327f1c2d09fec31ae38665911bd6383c10498dad.tar.xz
nixlib-327f1c2d09fec31ae38665911bd6383c10498dad.tar.zst
nixlib-327f1c2d09fec31ae38665911bd6383c10498dad.zip
lib.fixedPoints.extends: Add type and examples
Diffstat (limited to 'lib')
-rw-r--r--lib/fixed-points.nix20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/fixed-points.nix b/lib/fixed-points.nix
index 1b9504cb4533..8b76d2010e93 100644
--- a/lib/fixed-points.nix
+++ b/lib/fixed-points.nix
@@ -108,6 +108,26 @@ rec {
     fix g
     => { a = 11; b = 13; c = 24; }
     ```
+
+    Type:
+      extends :: (Attrs -> Attrs -> Attrs) # The overlay to apply to the fixed-point function
+              -> (Attrs -> Attrs) # A fixed-point function
+              -> (Attrs -> Attrs) # The resulting fixed-point function
+
+    Example:
+      f = final: { a = 1; b = final.a + 2; }
+
+      fix f
+      => { a = 1; b = 3; }
+
+      fix (extends (final: prev: { a = prev.a + 10; }) f)
+      => { a = 11; b = 13; }
+
+      fix (extends (final: prev: { b = final.a + 5; }) f)
+      => { a = 1; b = 6; }
+
+      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;