diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2018-11-21 18:27:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-21 18:27:09 +0100 |
commit | 9959d7d8b8f35341e6aecd2d6b87a70e240edbc3 (patch) | |
tree | 4a357bc9b81894ea29414cc9458f8cf4533289c2 /lib | |
parent | 97c4229c2de9c4f276bf14fe5bb4352740b16821 (diff) | |
parent | 3cc83dffca97e1da710ccc90777b3d3961ab3230 (diff) | |
download | nixpkgs-9959d7d8b8f35341e6aecd2d6b87a70e240edbc3.tar nixpkgs-9959d7d8b8f35341e6aecd2d6b87a70e240edbc3.tar.gz nixpkgs-9959d7d8b8f35341e6aecd2d6b87a70e240edbc3.tar.bz2 nixpkgs-9959d7d8b8f35341e6aecd2d6b87a70e240edbc3.tar.lz nixpkgs-9959d7d8b8f35341e6aecd2d6b87a70e240edbc3.tar.xz nixpkgs-9959d7d8b8f35341e6aecd2d6b87a70e240edbc3.tar.zst nixpkgs-9959d7d8b8f35341e6aecd2d6b87a70e240edbc3.zip |
Merge pull request #50532 from typetetris/add-extends-example
lib/fixed-points.nix: add an example for extends
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fixed-points.nix | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/fixed-points.nix b/lib/fixed-points.nix index 13e053b5aa7..7169c46fcbb 100644 --- a/lib/fixed-points.nix +++ b/lib/fixed-points.nix @@ -41,6 +41,18 @@ rec { # think of it as an infix operator `g extends f` that mimics the syntax from # Java. It may seem counter-intuitive to have the "base class" as the second # argument, but it's nice this way if several uses of `extends` are cascaded. + # + # To get a better understanding how `extends` turns a function with a fix + # point (the package set we start with) into a new function with a different fix + # point (the desired packages set) lets just see, how `extends g f` + # unfolds with `g` and `f` defined above: + # + # extends g f = self: let super = f self; in super // g self super; + # = self: let super = { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; }; in super // g self super + # = self: { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; } // g self { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; } + # = self: { foo = "foo"; bar = "bar"; foobar = self.foo + self.bar; } // { foo = "foo" + " + "; } + # = self: { foo = "foo + "; bar = "bar"; foobar = self.foo + self.bar; } + # extends = f: rattrs: self: let super = rattrs self; in super // f self super; # Compose two extending functions of the type expected by 'extends' |