query
On this page

genAttrs

lib.genAttrs

Docs pulled from | This Revision | 22 minutes ago


Generate an attribute set by mapping a function over a list of attribute names.

Inputs

names

Names of values in the resulting attribute set.

f

A function, given the name of the attribute, returns the attribute's value.

Type

genAttrs :: [ String ] -> (String -> Any) -> AttrSet

Examples

lib.attrsets.genAttrs usage example

genAttrs [ "foo" "bar" ] (name: "x_" + name)
=> { foo = "x_foo"; bar = "x_bar"; }
(lib.attrsets.genAttrs)

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

genAttrs =
    names:
    f:
    listToAttrs (map (n: nameValuePair n (f n)) names);