zaphyra's git: haumea

fork of https://github.com/nix-community/haumea

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
{ lib }:

# map each attribute in the given set into
# a list of attributes and subsequently merge them into
# a new attribute set with the specified mergeFun.

# Type: ({ ... } -> { ... } -> { ... }) -> (String -> a -> { ... }) -> { ... } -> { ... }

# Example:
#   concatMapAttrsWith (mergeAttrsButConcatOn "mykey")
#     (name: value: {
#       ${name} = value;
#       ${key} = value ++ value;
#     })
#     { x = "a"; y = "b"; }
#   => { x = "a"; y = "b"; mykey = [ "aa" "bb"]; }

let
  inherit (builtins)
    attrValues
    foldl'
    mapAttrs
    ;
  inherit (lib)
    flip
    pipe
    ;
in

merge: f: flip pipe [ (mapAttrs f) attrValues (foldl' merge { }) ]