My favorite interface for this type of operation is from Haskell's Data.Map, in pseudo-Haskell notation:
unionWithKey : (String -> a -> a -> a) -> Attrs a -> Atrs a -> Attrs a unionWith : (a -> a -> a) -> Attrs a -> Attrs a -> Attrs a unionWith = f: unionWithKey (_: f) This should be sufficient to write most other "merge" operations. The semantics are that keys common to both attrsets get their values passed into the function to figure out how it should be merged, and otherwise keys get passed through to the output attrsets unchanged. Then you can pick whether you want left-biased or right-biased behavior by simply passing in a function that selects the left or right element, or possibly merges them in more interesting ways (for example calling this function recursively) There are obvious analogs for intersections too. On Mon, May 29, 2017 at 11:19 AM, Sergiu Ivanov <siva...@colimite.fr> wrote: > Hello Tomasz, Domen, and Volth, > > Thus quoth Tomasz Czyż at 13:26 on Mon, May 29 2017: > > > > https://github.com/NixOS/nixpkgs/blob/master/lib/attrsets.nix#L413 is > also > > handy > > > > 2017-05-29 13:36 GMT+01:00 Domen Kožar <do...@dev.si>: > > > >> mkMerge can be used only with NixOS modules. > >> > >> I do remember some recursive merge function, but can't find it now. > >> > >> On Mon, May 29, 2017 at 2:29 PM, Volth <vo...@volth.com> wrote: > >> > >>> there is also lib.mkMerge to handle nested attrs > > My use case is waay simpler than modules (lucky me) :-) > > recursiveUpdate and especially recursiveUpdateUntil are some interesting > beasts, thanks for the reference. > > -- > Sergiu > > _______________________________________________ > nix-dev mailing list > nix-dev@lists.science.uu.nl > https://mailman.science.uu.nl/mailman/listinfo/nix-dev > >
_______________________________________________ nix-dev mailing list nix-dev@lists.science.uu.nl https://mailman.science.uu.nl/mailman/listinfo/nix-dev