about summary refs log tree commit diff
path: root/lib/attrsets.nix
AgeCommit message (Collapse)AuthorFilesLines
2024-06-20lib.intersectAttrs: Export from builtinsSilvan Mosberger1-1/+1
2024-04-15lib/attrsets: introduce mapCartesianProductGabriel Volpe1-0/+34
2024-04-15lib/attrsets: rename cartesianProductOfSets to cartesianProductGabriel Volpe1-5/+9
2024-04-06lib.hasAttrByPath: fix typo (#302042)Tharun Thennarasu1-2/+2
2024-03-19Apply suggestions from code reviewDaniel Sidhion1-0/+56
2024-03-19doc: manual fixup after migrationJohannes Kirschbauer1-71/+12
2024-03-15doc: migrate lib.attrsets to use doc-commentsJohannes Kirschbauer1-467/+1262
2024-03-06Merge pull request #292941 from adisbladis/lib-getattrfrompath-envSilvan Mosberger1-2/+1
lib.getAttrFromPath: Don't use errorMessage variable
2024-03-06Merge pull request #292938 from adisbladis/mapattrsrecursivecond-envSilvan Mosberger1-7/+6
lib.mapAttrsRecursiveCond: Eliminate intermediate one intermediate variable environment
2024-03-06Merge pull request #292937 from adisbladis/zipattrs-envSilvan Mosberger1-4/+1
lib.zipAttrs: Remove needless function wrapping
2024-03-06Merge pull request #292934 from adisbladis/lib-choosedevoutputSilvan Mosberger1-4/+1
lib.chooseDevOutputs: Remove needless function wrapping
2024-03-06doc: add details on `mapAttrsRecursive[Cond]` (#293509)Valentin Gagarin1-31/+46
* doc: add details on `mapAttrsRecursive[Cond]` from first reading it wasn't clear that `f` also takes the current attribute path. also the value f receives is tricky due to how the condition is evaluated. Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>
2024-03-03lib.getAttrFromPath: Don't use errorMessage variableadisbladis1-2/+1
We can just pass the error message on without creating an environment.
2024-03-03lib.mapAttrsRecursiveCond: Eliminate intermediate one intermediate variable ↵adisbladis1-7/+6
environment
2024-03-03lib.zipAttrs: Remove needless function wrappingadisbladis1-4/+1
Returning the partially applied `zipAttrsWith fn` is the same as `sets: zipAttrsWith fn sets`.
2024-03-03lib.chooseDevOutputs: Remove needless function wrappingadisbladis1-4/+1
Returning the partially applied `map getDev` is the same as `drvs: map getDev drvs`.
2024-02-09lib.attrsets: Remove unneeded polyfillsSilvan Mosberger1-9/+6
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-03lib: make deprecation warnings consistentAlois Wohlschlager1-4/+5
The deprecation warnings in lib were wildly inconsistent. Different formulations were used in different places for the same meaning. Some warnings used builtins.trace instead of lib.warn, which prevents silencing; one even only had a comment instead. Make everything more uniform.
2023-12-13lib/attrsets: Document and link Nix language operatorsRobert Hensing1-0/+24
2023-12-08lib.attrsets.hasAttrByPath: Document law and laziness, and test itRobert Hensing1-0/+7
2023-12-08lib.attrsets.longestValidPathPrefix: initRobert Hensing1-0/+65
Allows finding the most specific path that exists. This is useful for error messages relating to attribute paths.
2023-11-27Merge pull request #269552 from adisbladis/lib-matchattrs-list-allocsRobert Hensing1-9/+20
lib.attrsets.matchAttrs: Avoid some list allocations when walking structure
2023-11-27lib.attrsets.attrByPath: Don't allocate one extra list per lookup recursionadisbladis1-11/+21
Using `tail` in a recursive loop like this needlessly allocates. This changes the loop to look up by list index instead.
2023-11-27lib.attrsets.hasAttrByPath: Don't allocate one extra list per lookup recursionadisbladis1-6/+10
Using `tail` in a recursive loop like this needlessly allocates. This changes the loop to look up by list index instead.
2023-11-27lib.attrsets.matchAttrs: Avoid some list allocations when walking structureadisbladis1-9/+20
Benchmarks (`nix-instantiate ./. -A python3`): - Before: ``` json { "cpuTime": 0.29049500823020935, "envs": { "bytes": 4484216, "elements": 221443, "number": 169542 }, "gc": { "heapSize": 402915328, "totalBytes": 53086800 }, "list": { "bytes": 749424, "concats": 4242, "elements": 93678 }, "nrAvoided": 253991, "nrFunctionCalls": 149848, "nrLookups": 49612, "nrOpUpdateValuesCopied": 1587837, "nrOpUpdates": 10104, "nrPrimOpCalls": 130356, "nrThunks": 358981, "sets": { "bytes": 30423600, "elements": 1859999, "number": 41476 }, "sizes": { "Attr": 16, "Bindings": 16, "Env": 16, "Value": 24 }, "symbols": { "bytes": 236145, "number": 24453 }, "values": { "bytes": 10502520, "number": 437605 } } ``` - After: ``` json { "cpuTime": 0.2946169972419739, "envs": { "bytes": 3315224, "elements": 172735, "number": 120834 }, "gc": { "heapSize": 402915328, "totalBytes": 48718432 }, "list": { "bytes": 347568, "concats": 4242, "elements": 43446 }, "nrAvoided": 173252, "nrFunctionCalls": 101140, "nrLookups": 73595, "nrOpUpdateValuesCopied": 1587837, "nrOpUpdates": 10104, "nrPrimOpCalls": 83067, "nrThunks": 304216, "sets": { "bytes": 29704096, "elements": 1831673, "number": 24833 }, "sizes": { "Attr": 16, "Bindings": 16, "Env": 16, "Value": 24 }, "symbols": { "bytes": 236145, "number": 24453 }, "values": { "bytes": 8961552, "number": 373398 } } ```
2023-11-20lib: Take advantage of section descriptionsSilvan Mosberger1-1/+1
See https://github.com/nix-community/nixdoc/releases/tag/v2.6.0
2023-10-10Merge pull request #254452 from flyingcircusio/lib-attrsToListSilvan Mosberger1-0/+30
lib.attrsets.attrsToList: add function
2023-10-10lib.attrsets.attrsToList: add functionOliver Schmidt1-0/+30
For transforming back between lists and attrsets, it makes sense to have a quasi-inverse of `builtins.listToAttrs` available as a library function. Co-authored-by: Silvan Mosberger <github@infinisil.com> Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-09-27lib.attrsets.foldlAttrs: Make stricterSilvan Mosberger1-5/+5
See the parent commit for the same change to lib.lists.foldl'
2023-09-27lib.lists.foldl': Make strict in the initial accumulatorSilvan Mosberger1-1/+1
To maintain backwards compatibility, this can't be changed in the Nix language. We can however ensure that the version Nixpkgs has the more intuitive behavior.
2023-07-18lib.attrsets.mergeAttrsList: initSilvan Mosberger1-0/+36
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-06-23lib/attrsets: remove unused let bindingsfigsoda1-1/+1
2023-05-31lib.concatMapAttrs: Simplify stack traceRobert Hensing1-1/+5
2023-04-19lib: add missing removeAttrs builtinzimbatm1-1/+1
I'm expecting all the builtins.* functions to be available in lib.*
2023-03-11init: lib.foldlAttrshsjobeki1-0/+60
- provide comprehensive example - add unit test
2023-01-30lib: standardise attrset type syntaxColin Arnott1-5/+5
There are a number of different syntaxes used for attrset type signatures in our doc strings, this change standardises upon one that uses :: for specifying attribute type, and ; terminators to be consistent with nix syntax. There are no bugs in the functions themselves, just that different syntaxes may confuse new users.
2023-01-25Update lib/attrsets.nixAdam Joseph1-1/+4
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-01-22attrsets: clarify that mapAttrs maps over *leaf* attrsAdam Joseph1-2/+4
2023-01-02lib: Fix mismatched quotes in `lib.*` doc commentsYoshiRulz1-10/+10
caused problems for automated rich text generation such as https://teu5us.github.io/nix-lib.html#customisation-functions
2022-12-24attrsets: fix and add some doc typeshsjobeki1-25/+36
2022-12-17lib: fix typosfigsoda1-1/+1
2022-12-08doc: auto-generate asserts and attrset library docsRyan Mulligan1-89/+364
If all the docs are auto-generated, it should be easier to convert them to Commonmark. Co-Authored-By: Valentin Gagarin <valentin.gagarin@tweag.io> Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
2022-11-17lib/attrsets: add concatMapAttrsfigsoda1-1/+20
2022-11-17lib/attrsets: simplify chooseDevOutputsfigsoda1-1/+1
2022-09-25unionOfDisjoint: use builtins.intersectAttrsAdam Joseph1-5/+8
This brings two benefits: 1. The complete list of collisions is printed in the whenever any colliding attribute is accessed. 2. The sets are intersected using a C++ primitive, which runs in O(n) time (intersecting pre-sorted lists) with small constants rather than interpreted Nix code. Thanks to @toonn for prompting this improvement.
2022-09-12note that `unionOfDisjoint` is commutative, unlike //Adam Joseph1-1/+2
2022-09-12lib/attrsets.nix: add unionOfDisjointAdam Joseph1-0/+10
2022-05-10lib.foldAttrs: Clarify exampleRobert Hensing1-1/+1
2022-03-19Merge pull request #147077 from Infinisil/updateAttrPathsRobert Hensing1-2/+113
Introduce `lib.updateManyAttrsByPath`
2022-03-18lib.attrsets: Introduce updateManyAttrsByPathSilvan Mosberger1-1/+98