Skip to content

Commit

Permalink
lib: Add composeExtensions for composing extension functions
Browse files Browse the repository at this point in the history
(cherry picked from commit 0a15af2)
  • Loading branch information
shlevy committed Apr 11, 2017
1 parent 32491fc commit 2d02be0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/trivial.nix
Expand Up @@ -53,6 +53,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: { })
Expand Down

0 comments on commit 2d02be0

Please sign in to comment.