From 0a15af2ed170b30636a264b6b535a9327effddc5 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 7 Apr 2017 14:03:40 -0400 Subject: [PATCH] lib: Add composeExtensions for composing extension functions --- lib/trivial.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/trivial.nix b/lib/trivial.nix index 40499b2b5092..acbd687dd98f 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -80,6 +80,15 @@ rec { # argument, but it's nice this way if several uses of `extends` are cascaded. extends = f: rattrs: self: let super = rattrs self; in super // f self super; + # Compose two extending functions of the type expected by 'extends' + # into one where changes made in the first are available in the + # 'super' of the second + composeExtensions = + f: g: self: super: + let fApplied = f self super; + super' = super // fApplied; + in fApplied // g self super'; + # Create an overridable, recursive attribute set. For example: # # nix-repl> obj = makeExtensible (self: { })