summaryrefslogtreecommitdiffstats
path: root/lib/fixed-points.nix
diff options
context:
space:
mode:
authorWill Fancher <elvishjerricco@gmail.com>2017-07-11 21:33:26 -0400
committerWill Fancher <elvishjerricco@gmail.com>2017-07-12 18:35:22 -0400
commit08021dd8253b6fa6ab625cd925e4bd3f09f1d8b4 (patch)
tree3cf809c8899025b0dc02c5c6c23ca318ff2744d1 /lib/fixed-points.nix
parent2c1097a83b2a689bf2f58f2c9d24a47441460750 (diff)
Added `makeExtensibleWithInterface`
Diffstat (limited to 'lib/fixed-points.nix')
-rw-r--r--lib/fixed-points.nix19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/fixed-points.nix b/lib/fixed-points.nix
index a11b5a6f4bdc..5039a45cc3f1 100644
--- a/lib/fixed-points.nix
+++ b/lib/fixed-points.nix
@@ -71,8 +71,19 @@ rec {
# Same as `makeExtensible` but the name of the extending attribute is
# customized.
- makeExtensibleWithCustomName = extenderName: rattrs:
- fix' rattrs // {
- ${extenderName} = f: makeExtensibleWithCustomName extenderName (extends f rattrs);
- };
+ makeExtensibleWithCustomName = extenderName: makeExtensibleWithInterface
+ (fixedPoint: extend: fixedPoint // { ${extenderName} = extend; });
+
+ # Similar to `makeExtensible`, but expects you to implement the
+ # final interface for the result. Specifically, it takes an extra
+ # argument: a function that takes the final result and the `extend`
+ # function as arguments, and returns a transformed result
+ # (preferably one that contains the `extend` function). This is
+ # mainly useful for getting to choose what to name the `extend`
+ # function in the resulting attribute set. But it's also useful for
+ # having an internal structure that extensions can see, but the user
+ # facing code cannot.
+ makeExtensibleWithInterface = interface: fext: interface
+ (fix' fext)
+ (f: makeExtensibleWithInterface interface (extends f fext));
}