korora icon indicating copy to clipboard operation
korora copied to clipboard

Add key-dependent attrsOf type

Open prescientmoon opened this issue 2 years ago • 0 comments

It is sometimes useful for the type of attributes in attrsOf to depend on the current key. My internal implementation looks something like this

    dependentAttrsOf =
      name: mkType:
      let withErrorContext = addErrorContext "in ${name} value";
      in
      k.typedef' name
        (v:
        if ! lib.isAttrs v then
          typeError name v
        else
          withErrorContext
            (mkVerify
              (lib.mapAttrsToList (k: _: mkType k) v)
              v));

The mkVerify is an internal function of mine which looks similar to all' in your implementation, except it shows every error instead of the first one.

prescientmoon avatar Dec 22 '23 18:12 prescientmoon